Confusión de Docker WORKDIR

Confusión de Docker WORKDIR

Soy un principiante con Docker y tengo un Dockerfile muy básico para practicar.

FROM debian:latest
WORKDIR /init
COPY hello_world.sh .
RUN hello_world.sh
CMD [ "/bin/bash" ]

Después de intentar construir la imagen, aparece esto:

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

Si modifico la directiva RUN y establezco una ruta absoluta/init/hola_mundo.sh, funciona bien. Según la descripción, el Dockerfile anterior debería funcionar.

De la referencia de Dockerfile:

The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile.

¿Qué entendí mal?

Respuesta1

Intentar RUN ./hello_world.sh. El hecho de queDIRTRABAJOutilizado por RUN detective, no significa que esté automáticamente en la RUTA. Esto sigue siendo sólo eldirectorio de trabajodonde se ejecuta un proceso.

información relacionada