11

I have a Dockerfile like this:

FROM alpine

COPY setup.sh /setup.sh

CMD ["/setup.sh"]

My setup.sh is like this:

#!/bin/sh

echo "hello world"

Tried to run these commands:

docker build .
docker run --name test 61230f9f45ad

Error returned is this:

standard_init_linux.go:195: exec user process caused "no such file or directory"

I'm using Powershell on Windows 10 LTSB, docker version is 17.12.0-ce, build c97c6d6. Why?

Cris
  • 213

4 Answers4

18

It is probably the Windows-style line endings that break it. Here's what the file looks like when saved with Windows line endings, but read in Unix style:

#!/bin/sh^M
^M
echo "hello world"^M 

When interpreting the shebang (#!), exec will see an extra carriage return (denoted CR, \r, ^M) and fail to find /bin/sh^M:

$ exec ./setup.sh
bash: setup.sh: /bin/sh^M: bad interpreter: No such file or directory 

Save the file with Unix-style line endings. On Windows, decent text editors (Sublime Text, Notepad++, any IDE, etc.) should be able to do it. There is also a simple command-line tool called dos2unix, which does exactly what you'd expect it to.

Norrius
  • 538
6

The Alpine image uses busybox, and there is no shell in busybox since it isn't really meant for humans.

For your information replace

CMD ["/setup.sh"]

by:

CMD /bin/busybox ls -al /bin

You get:

lrwxrwxrwx    1 root     root            12 Jan  9 19:37 ash -> /bin/busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 base64 -> /bin/busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 bbconfig -> /bin/busybox
-rwxr-xr-x    1 root     root        805024 Dec 12 10:42 busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 cat -> /bin/busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 chgrp -> /bin/busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 chmod -> /bin/busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 chown -> /bin/busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 conspy -> /bin/busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 cp -> /bin/busybox

[... snip ...]

lrwxrwxrwx    1 root     root            12 Jan  9 19:37 tar -> /bin/busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 touch -> /bin/busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 true -> /bin/busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 umount -> /bin/busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 uname -> /bin/busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 usleep -> /bin/busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 watch -> /bin/busybox
lrwxrwxrwx    1 root     root            12 Jan  9 19:37 zcat -> /bin/busybox

In addition, if you look at /lib the same way, you'll find that the usual libs aren't there since busybox uses musl instead of glibc.

Typically, whatever is done in your setup.sh should be done with RUN instructions in the Dockerfile anyway?

PS: Incidentally,

standard_init_linux.go:195: exec user process caused "no such file or directory"

means that either the executable is not found or one of its required libraries is not found, which makes debugging the Dockerfile quite difficult.

xenoid
  • 8,888
1

It should use a Unix-style line endings instead of Windows. This problem occurs for me as well on Windows 10.

You should run the following command before cloning the repository:

git config --global core.autocrlf false

Then clone the repository and proceed.

harmider
  • 111
1

try to put in CMD or Entrypoint ["/bin/sh","/setup.sh"] (or ["/bin/ash","/setup.sh"]) instead of just ["/setup.sh"]. It works for me in busybox container