8

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?

2
  • Works for me on a Linux host, but it's docker run, not docker start (start doesn't even have the option --name). – Norrius Mar 25 '18 at 17:20
  • oh yes I had a little lapsus, modified – Cris Mar 25 '18 at 17:50
16

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.

1
  • Even on Linux you can have CRLF in a Dockerfile... – xenoid Mar 25 '18 at 17:58
3

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.

3
  • Didn't mark as solution because it didn't directly solve this problem. This is good to know tough. – Cris Mar 25 '18 at 22:38
  • So i assume that the other answer solved the problem? – xenoid Mar 26 '18 at 5:53
  • Yes it did solve this problem – Cris Mar 26 '18 at 5:58
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.