Can't run script file in docker, no such file or directory
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.
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.