Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker entrypoint not found although in PATH (and executable)

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);

like image 258
pkaramol Avatar asked Jul 26 '18 07:07

pkaramol


People also ask

Does docker exec use ENTRYPOINT?

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”]

Can you have both CMD and ENTRYPOINT in Dockerfile?

#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.

Does CMD override ENTRYPOINT?

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.

Can I use both ENTRYPOINT and CMD?

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.


2 Answers

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).

like image 57
joelnb Avatar answered Oct 19 '22 18:10

joelnb


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.

like image 40
Bob Avatar answered Oct 19 '22 19:10

Bob