Docker WORKDIR 혼란

Docker WORKDIR 혼란

저는 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 지시어를 수정하고 절대 경로를 설정하면/init/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 감지기가 사용한다고 해서 PATH에 자동으로 포함되는 것은 아닙니다. 아직은 이것뿐이다.작업 디렉토리프로세스가 실행되는 곳.

관련 정보