7

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

pkaramol
  • 16,451
  • 43
  • 149
  • 324

3 Answers3

12

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

joelnb
  • 1,426
  • 11
  • 14
  • 2
    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. – bunji Nov 01 '19 at 14:43
  • 1
    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](https://github.com/moby/buildkit/blob/master/frontend/dockerfile/instructions/parse.go#L397) 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 quotes – joelnb Nov 01 '19 at 15:33
  • It's stuff like this that make me wanna quit tech! – Dan Garland Sep 30 '21 at 19:29
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.

Bob
  • 5,809
  • 5
  • 36
  • 53
0

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.

Mohit
  • 191
  • 1
  • 12