私は Docker の初心者で、練習用に非常に基本的な Dockerfile を持っています。
FROM debian:latest
WORKDIR /init
COPY hello_world.sh .
RUN hello_world.sh
CMD [ "/bin/bash" ]
イメージをビルドしようとすると、次のようになります。
Sending build context to Docker daemon 3.072kB
Step 1/5 : FROM debian:latest
---> ee11c54e6bb7
Step 2/5 : WORKDIR /init
---> Using cache
---> 605ee1ff67e9
Step 3/5 : COPY hello_world.sh .
---> Using cache
---> f544ee4e93b8
Step 4/5 : RUN hello_world.sh
---> Running in c4cbd6389bc2
/bin/sh: 1: hello_world.sh: not found
The command '/bin/sh -c hello_world.sh' returned a non-zero code: 127
RUNディレクティブを変更して絶対パスを設定するとhello_world.sh を初期化します。、うまく動作します。説明に基づくと、上記の Dockerfile は動作するはずです。
Dockerfile リファレンスより:
The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile.
何を誤解したのでしょうか?
答え1
試してみてくださいRUN ./hello_world.sh
。ワークディレクトリRUN Detective によって使用されるが、PATH に自動的に含まれることを意味するわけではない。これはまだ作業ディレクトリプロセスが実行される場所。