0
0

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でRUNコマンド実行時の注意点

Posted at

Dockerfileからイメージを作成する際に、apt-getでインストールする時にハマったので、その備忘録です。

Dockerfile
# 悪い例
FROM ubuntu
RUN apt-get update
RUN apt-get install -y ruby
RUN apt-get install -y python

# 良い例
FROM ubuntu
RUN apt-get update && apt-get install -y \
    ruby \
    python

RUN apt-get updateとapt-get installは、連結して書くようにしないといけません。
悪い例のように、連結せず別々に実行すると、apt-get install命令が失敗するからです。

イメージを構築後、Dockerはレイヤーを全てキャッシュします。
Dockerがファイルを冒頭から読み込んでいき、命令の変更を認識すると、前回に作成したキャッシュを再利用します。
そのため、installコマンドを編集していたとしても、apt-get updateコマンドは実行されずキャッシュされたバージョンが使われてしまいます。
そうすると古いバージョンがinstallされてしまいますー。

ちゃんと公式ドキュメント読まないとですね!

参考サイト:
http://docs.docker.jp/engine/userguide/eng-image/dockerfile_best-practice.html

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?