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

前端 未结 11 1012
清歌不尽
清歌不尽 2021-01-31 08:02

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

<
相关标签:
11条回答
  • 2021-01-31 08:15

    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)

    0 讨论(0)
  • 2021-01-31 08:18

    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/

    0 讨论(0)
  • 2021-01-31 08:19

    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.

    0 讨论(0)
  • 2021-01-31 08:20

    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\"}" \
    ]
    
    0 讨论(0)
  • 2021-01-31 08:21

    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

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

    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?

    0 讨论(0)
  • 2021-01-31 08:22

    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

    0 讨论(0)
提交回复
热议问题