Docker entrypoint not found although in PATH (and executable)
Asked Answered
G

3

8

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

Gamal answered 26/7, 2018 at 7:41 Comment(0)
I
13

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

Insect answered 26/7, 2018 at 8:1 Comment(3)
Extra detail: In the documentation you link to it mentions that the reason for double quotes is because docker parses the value as a json array.Midsection
Thanks for the extra info! This made me think about why when it uses single quotes they are not printed in the error. As I found the answer I though I would share in case it's interesting to anyone else. When docker finds an ENTRYPOINT command it uses parseEntrypoint which calls parseShellDependentCommand in the same file. This then checks if the command was valid JSON & if not, prepends the shell to the command. So it actually runs /bin/sh ['docker-entrypoint.sh'] and the shell swallows the quotesInsect
It's stuff like this that make me wanna quit tech!Recondition
L
3

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.

Liberal answered 15/8, 2019 at 15:25 Comment(0)
S
1

I face the same issue and the reason i found on another stack over flow answer is line encoding difference, I got my docker file from one of open source project, and I building and deploying my file on Docker Desktop for Winodw, I changed my Docker & .sh file encoding from CRLF -> LF and it worked, you can use VS code for same it have bootom right corner option to convert CRLF to LF.

Scandium answered 29/10, 2021 at 9:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.