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

2019-03-12 10:18发布

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 <gilani@payload.tech>

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'"]

8条回答
祖国的老花朵
2楼-- · 2019-03-12 10:46

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.

查看更多
倾城 Initia
3楼-- · 2019-03-12 10:52

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.

查看更多
叛逆
4楼-- · 2019-03-12 10:53

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: How to change line-ending settings and here http://willi.am/blog/2016/08/11/docker-for-windows-dealing-with-windows-line-endings/

查看更多
萌系小妹纸
5楼-- · 2019-03-12 10:56

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.

查看更多
手持菜刀,她持情操
6楼-- · 2019-03-12 10:58

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

查看更多
兄弟一词,经得起流年.
7楼-- · 2019-03-12 11:02

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'],
  }
查看更多
登录 后发表回答