My Dockerfile:
FROM my-image-base
COPY src src
RUN chmod x src/script.sh
ENTRYPOINT ['/src/script.sh']
After successful build:
docker run created_image
/bin/sh: [/src/script.sh]: No such file or directory
docker run --entrypoint /src/script.sh created_image
script runs successfully
I feel like I'm overwriting the default ENTRYPOINT with the same thing but it behaves differently. Am I misunderstanding something?
CodePudding user response:
No, it's not the same thing, because your ENTRYPOINT
is invalid.
ENTRYPOINT
has two forms:
The shell command form:
ENTRYPOINT command param1 param2
and the
exec
form:ENTRYPOINT ["executable", "param1", "param2"]
Which of the two forms are you using here? If you answer "the second", you have been subtly led astray, because you have single-quotes '
there instead of double-quotes "
!
As specified in the docs:
Note: The
exec
form is parsed as a JSON array, which means that you must use double-quotes ("
) around words not single-quotes ('
).
So, you actually have the first form, the shell command form.
Docker will pass your "command" to the shell, like this:
/bin/sh -c "['/src/script.sh']"
Due to the way quotes work when parsing shell command lines, this ends up being equivalent to typing [/src/script.sh]
into your shell. The shell then rightfully complains that that's not a valid command.