1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Docker】Dockerfileの基本的な書き方

Posted at

Dockerfileとは

Dockerイメージを作成するために必要な設定などを管理するファイルのこと。
このDockerfileをビルドすることでDockerイメージを作成できる。

基本的な書き方

Dockerfileで使われるコマンドをいくつかまとめておく。

FROM

ベースとなるイメージを指定する。

FROM <イメージ名>:<バージョン>

バージョンを指定しない場合は、最新バージョンが取得される。

WORKDIR

コマンドを実行する作業ディレクトリを指定する。

WORKDIR <パス>

もし、ディレクトリが存在しない場合は自動作成される。

RUN

イメージ作成時に実行したいコマンド指定する。

RUN <実行したいコマンド>

複数コマンドを実行させたい場合は&&で連結して1つのRUNでまとめることができる。

COPY

指定されたファイルやディレクトリをコピーする。

COPY <コピー元> <コピー先>

ENV

Dockerfile内で使用する環境変数を設定する。

ENV <環境変数名>=<値>

CMD

コンテナ起動時に実行するコマンドを指定する。基本的には末尾で1度だけ実行される。

CMD ["<コマンド>", "<オプション>", ...]
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?