Movatterモバイル変換


[0]ホーム

URL:


LoginSignup
28

Go to list of users who liked

35

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のTips

Last updated atPosted at 2014-07-13

Dockerfileを書いていて詰まったところなど。

WORKDIR は ADD には効かない

公式ドキュメントにちゃんと書いてあるが、WORKDIRが効くのはRUNCMDENTRYPOINTのみ。
下記のように書いても/var/appには配置されません。

Dockerfile
WORKDIR /var/appADD Gemfile.local ./

WORKDIR のバグ

下記のように記載しても、WORKDIRのディレクティブで環境変数が効かない。

Dockerfile
ENV APP_PATH /var/appWORKDIR${APP_PATH}RUN bundleinstall

これはバグのようで、修正されるまでは直接書くしか無さそう。

Dockerfile
WORKDIR /var/appRUN bundleinstall

EXPOSE のバグ

下記のように記載しても、EXPOSEのディレクティブで環境変数が効かない。
これもバグっぽい。

Dockerfile
ENV PORT 80EXPOSE${PORT}

実行順序について

Dockerfileにかかれている内容は一行毎にコンテナに入り実行されているみたいなので、下記のような書き方だと上手く実行されない。

Dockerfile
RUN /etc/init.d/mysqld startRUN mysqladmin-u root password"password"RUN /etc/init.d/mysqld stop

これは1行目でmysqlを実行したあとに状態を保存し、再度立ち上げたコンテナ上で2行目が実行されているから。(たぶん)

なので、以下のようにまとめて書けばOK。(見難いので改行しています)

Dockerfile
RUN /etc/init.d/mysqld start&&\    mysqladmin-u root password"password"&&\    /etc/init.d/mysqld stop

RUN の上限

dockerのv0.7.2以降における、AUFXの積み上げ可能なRUNの上限は127 みたいです。
参考:stackoverflow

なので、&&とかで節約するのはいいことです。

28

Go to list of users who liked

35
1

Go to list of comments

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
28

Go to list of users who liked

35

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?


[8]ページ先頭

©2009-2025 Movatter.jp