3
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 1 year has passed since last update.

Dockerfileでcd使いたい場合

Posted at

失敗例

「RUN cd /tmp」を実行しても次の行ではカレントディレクトリは移動したことにならないので、「RUN cd ./tesh.sh」の実行で、そんなファイル無いというエラーになる。

Dockerfile
RUN cd /tmp
RUN cd ./tesh.sh

方法①

cd の代わりに WORKDIR を使う。
ただし、以降の命令のカレントディレクリも変わってしまうので、それは困るというなら「方法②」

Dockerfile
WORKDIR /tmp
RUN ./tesh.sh

方法合②

「&&」で1行に命令をまとめる。一時的にカレントディレクトリを変えるイメージ。「RUN cd /tmp && ./test.sh」以降の命令では、WORKDIRで設定したカレントディレクトリは変わらない。

Dockerfile
RUN cd /tmp && ./test.sh
3
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
3
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?