I am creating a simple image with the following Dockerfile
FROM docker:latest
COPY docker-entrypoint.sh /usr/local/bin
ENTRYPOINT ['docker-entrypoint.sh']
Inside my container:
/ # ls -al $(which docker-entrypoint.sh)
-rwxrwxr-- 1 root root 476 Jul 26 07:30 /usr/local/bin/docker-entrypoint.sh
So the entrypoint file is both in the PATH
and executable;
But when running
docker run -v /var/run/docker.sock:/var/run/docker.sock -it imageinit
/bin/sh: [docker-entrypoint.sh]: not found
I am aware of this SO question, but this is about the problem of PATH
and file permissions (already addressed);
Docker ENTRYPOINT Unlike CMD commands, ENTRYPOINT commands cannot be ignored or overridden—even when the container runs with command line arguments stated. A Docker ENTRYPOINT instruction can be written in both shell and exec forms: Exec form: ENTRYPOINT [“executable”, “parameter1”, “parameter2”]
#6 Using ENTRYPOINT with CMD Still, they both can be used in your Docker file. There are many such cases where we can use both ENTRYPOINT and CMD. The thing is that you will have to define the executable with the ENTRYPOINT and the default parameters using the CMD command. Maintain them in exec form at all times.
CMD: Sets default parameters that can be overridden from the Docker Command Line Interface (CLI) while running a docker container. ENTRYPOINT: Default parameters that cannot be overridden while executing Docker Containers with CLI parameters.
Example of using CMD and ENTRYPOINT togetherIf both ENTRYPOINT and CMD are present, what is written in CMD is executed as an option of the command written in ENTRYPOINT. If an argument is added at the time of docker run , the contents of CMD will be overwritten and the ENTRYPOINT command will be executed.
Interestingly your issues seems to be with the type of quotes you have chosen to use. If you change this line:
ENTRYPOINT ['docker-entrypoint.sh']
to
ENTRYPOINT ["docker-entrypoint.sh"]
then everything starts to work as expected.
If you check the documentation for the type of ENTRYPOINT
you are using all of the examples have double quotes.
I suspect what is happening when you use the single quotes is that docker is parsing this as the shell form of ENTRYPOINT
and trying to execute a script called [docker-entrypoint.sh]
which would explain the error message (as obviously no script of that name will exist).
I was getting exactly the same error under the same circumstances (although no single quotes problem) when the docker-entrypoint.sh
script contained carriage returns, converting the script with dos2unix docker-entrypoint.sh
fixed the issue for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With