3
2

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 5 years have passed since last update.

Dockerfileを使ったイメージ作成 Docker入門

Last updated at Posted at 2017-01-28

Dockerfileによる自動構築のメリット

  • 構築の手間を省力化
  • ミスの低減
  • 導入手順書になりうる

Dockerfileの作成

ファイル名

Dockerfile

記載例

# Dockerイメージ名を指定
FROM centos:latest

# パッケージアップデートなどを実行させる
RUN yum update -y && yum clean all

# コンテナが外部に開放するポート番号指定
EXPOSE 80

記載できるInstructions

FROM <image>
FROM <image>:<tag>

MAINTAINER <name>

RUN <command>
RUN /bin/bash -c 'source $HOME/.bashrc ; echo $HOME'

CMD ["executable","param1","param2"]
CMD [ "sh", "-c", "echo $HOME" ]

EXPOSE <port> [<port>...]
EXPOSE 80

ENV <key> <value>
ENV myName John Doe

COPY <src>... <dest>
COPY requirements.txt /tmp/

ADD <src>... <dest>
ADD http://example.com/big.tar.xz /usr/src/things/

ENTRYPOINT
ENTRYPOINT ["s3cmd"]

VOLUME ["/data"]

WORKDIR /tmp

Dockerイメージのビルド

docker build -t <image_name> .

# Dockerfile指定する場合は -f <Dockerfile_path> オプション

その他メモ

  • キャッシュを使わない 2度めのbuildでyum等が行われない可能性を排除 --no-cache=true
  • cdコマンドを使わない WORKDIR をつかう
  • .dockerignore 無視したいファイル・ディレクトリを記載
  • tarアーカイブへの保管 docker export web0001 > web0001.tar 停止しているコンテナを指定する

参考

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?