Why won't my docker-entrypoint.sh execute?

DockerDockerfile

Docker Problem Overview


My ENTRYPOINT script doesn't execute and throws standard_init_linux.go:175: exec user process caused "no such file or directory". Why so?

Doesn't Work

$ docker build -t gilani/trollo . && docker run gilani/trollo
Sending build context to Docker daemon   126 kB
Step 1 : FROM vault:latest
 ---> 1f127f53f8b5
Step 2 : MAINTAINER Amin Shah Gilani <gilani@payload.tech>
 ---> Using cache
 ---> 86b885ca1c81
Step 3 : COPY vaultConfig.json /vault/config
 ---> Using cache
 ---> 1a2be2fa3acd
Step 4 : COPY ./docker-entrypoint.sh /
 ---> Using cache
 ---> 0eb7c1c992f1
Step 5 : RUN chmod +x /docker-entrypoint.sh
 ---> Running in 251395c4790f
 ---> 46aa0fbc9637
Removing intermediate container 251395c4790f
Step 6 : ENTRYPOINT /docker-entrypoint.sh
 ---> Running in 7434f052178f
 ---> eca040859bfe
Removing intermediate container 7434f052178f
Successfully built eca040859bfe
standard_init_linux.go:175: exec user process caused "no such file or directory"

Dockerfile:

FROM vault:latest

MAINTAINER Amin Shah Gilani <[email protected]>

COPY vaultConfig.json /vault/config

COPY ./docker-entrypoint.sh /

RUN chmod +x /docker-entrypoint.sh

ENTRYPOINT ["/docker-entrypoint.sh"]

docker-entrypoint.sh:

#!/bin/bash

echo 'Hello World!'

Works

$ docker build -t gilani/trollo . && docker run gilani/trollo
Sending build context to Docker daemon   126 kB
Step 1 : FROM vault:latest
 ---> 1f127f53f8b5
Step 2 : MAINTAINER Amin Shah Gilani <gilani@payload.tech>
 ---> Using cache
 ---> 86b885ca1c81
Step 3 : COPY vaultConfig.json /vault/config
 ---> Using cache
 ---> 1a2be2fa3acd
Step 4 : ENTRYPOINT echo 'hello world'
 ---> Using cache
 ---> ef5792a1f252
Successfully built ef5792a1f252
'hello world'

Dockerfile:

FROM vault:latest

MAINTAINER Amin Shah Gilani <gilani@payload.tech>

COPY vaultConfig.json /vault/config

ENTRYPOINT ["echo", "'hello world'"]

Docker Solutions


Solution 1 - Docker

I was tearing my hair out with an issue very similar to this. In my case /bin/bash DID exist. But actually the problem was Windows line endings.

In my case the git repository had an entry point script with Unix line endings (\n). But when the repository was checked out on a windows machine, git decided to try and be clever and replace the line endings in the files with windows line endings (\r\n).

This meant that the shebang didn't work because instead of looking for /bin/bash, it was looking for /bin/bash\r.

The solution for me was to disable git's automatic conversion:

git config --global core.autocrlf input

Then check out the repository again and rebuild.

Some more helpful info here: https://stackoverflow.com/questions/10418975/how-to-change-line-ending-settings and here http://willi.am/blog/2016/08/11/docker-for-windows-dealing-with-windows-line-endings/

Solution 2 - Docker

the vault:latest image does not contain /bin/bash which you try to call with your shebang #!/bin/bash. You should either change that to #!/bin/sh or completely remove the shebang from your script.

Solution 3 - Docker

Without seeing your image, my initial idea is that you don't have /bin/bash in your image. Changing the first line of your docker-entrypoint.sh to:

#!/bin/sh

will likely resolve it.

Solution 4 - Docker

Another possibility:

Check that the file is not saved with Windows line endings (CRLF). If it is, save it with Unix line endings (LF) and it will be found.

Solution 5 - Docker

I struggled for hours because I haven't noticed anywhere explained that you need to copy the file in the location where the VM can access the file, preferably globally like so:

COPY docker-entrypoint.sh /usr/local/bin/

(I had thought it should just be automatically accessible since it's part of the dockerfile context)

Solution 6 - Docker

Gosh I struggled for 2–3 hours!! Thanks to @Ryan Allen For my case it was CRLF problem. I am working on puppet manifests over ATOM for jenkins setup. Make sure if you are using ATOM or any other IDE on windows, when you take your file ( especially .sh) to unix, convert it to unix format. It worked like magic once converted. Here is what I added in my puppet file:

  exec {'dos2unix':
    path      => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/opt/puppetlabs/bin'],
    command   => 'dos2unix /dockerwork/puppet/jenkins/files/*',
    subscribe => File['/dockerwork/puppet/jenkins/files/init.sh'],
  }

Solution 7 - Docker

I came here with a similar issue while troubleshooting my attempt to build a Dockerfile "entry point" (entrypoint.sh) bash shell script (to be executed within the .NET Core SDK 2.2 image). The start of the script had the line #!/bin/bash, and during execution of docker-compose up (after successfully building with docker-compose build, the logging reported web_1 | ./entrypoint.sh: line 1: #!/bin/bash: No such file or directory.

Checking the file with VS Code, I noticed it was reporting the following encoding:

> UTF-8 with BOM

enter image description here

Clicking on this, I would get the option to Save with encoding:

enter image description here

I chose to save as UTF-8 (utf8), which resolved the issue.

NOTE: I also found this SO article What's the difference between UTF-8 and UTF-8 without BOM?

Solution 8 - Docker

Another reason this error comes up is if your Windows User password changes.

In my case my entrypoint.sh line endings were LF but I was still getting the error. Our admin has a mandatory password reset about every month or so. Whenever this happens I would run into the error. If this is your reason you may need to reset your credentials in docker settings under "Shared Drives".

Unselect the drive and apply. Then reselect the drive and apply. It will prompt you for your password.

Solution 9 - Docker

Sorry for hacking -- this is not a response to the question, but a description of a different problem and it's solution that has the same symptoms.

I had

ENTRYPOINT ["/usr/bin/curl", "-X", "POST", "http://myservice:8000", \
              "-H", "Content-Type: application/json", \
              "-d", '{"id": "test"}' \
]

I was getting the error:

/bin/bash: [/usr/bin/curl,: No such file or directory

It turns out it's the single quotes that messed it up. Docker documentation has a note:

> The exec form is parsed as a JSON array, which means that you must use double-quotes (“) around words not single-quotes (‘). > Blockquote

Solution -- use double quotes instead of single and escape nested double quotes:

ENTRYPOINT ["/usr/bin/curl", "-X", "POST", "http://myservice:8000", \
              "-H", "Content-Type: application/json", \
              "-d", "{\"id\": \"test\"}" \
]

Solution 10 - Docker

My case was that the alpine image I was using didn't come with bash at all... RUN apk-install bash did the trick obviously

Solution 11 - Docker

This problem is to do with line endings and I solved it with the solution below

Convert the DOS file to a unix format. This removes any wired line endings.

dos2unix - is available in alpine as well as other Linux distributions.

I used it like so: RUN apk add dos2unix && dos2unix /entry.sh

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAmin Shah GilaniView Question on Stackoverflow
Solution 1 - DockerDaniel HowardView Answer on Stackoverflow
Solution 2 - DockerP.J.MeischView Answer on Stackoverflow
Solution 3 - DockerBMitchView Answer on Stackoverflow
Solution 4 - DockerRyan AllenView Answer on Stackoverflow
Solution 5 - DockerDaniel KatzView Answer on Stackoverflow
Solution 6 - DockerAshish K SrivastavaView Answer on Stackoverflow
Solution 7 - DockerAdam CoxView Answer on Stackoverflow
Solution 8 - DockerdcinadrView Answer on Stackoverflow
Solution 9 - DockerAnton DaneykoView Answer on Stackoverflow
Solution 10 - DockerPainy JamesView Answer on Stackoverflow
Solution 11 - DockerFerdie De OliveiraView Answer on Stackoverflow