Alan
Alan

Reputation: 3745

Ubuntu container can't find shell script

I'm new to Docker, and am trying a simple example of an Ubuntu container that runs a shell script. I'm on Windows 10 with Docker 17.09.0-ce.

My shell script is simply:

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

My Dockerfile is:

FROM ubuntu:14.04
WORKDIR /usr/local/bin
COPY shelltest.sh shelltest.sh
ENTRYPOINT ["/usr/local/bin/shelltest.sh"]

I've tried various forms of ENTRYPOINT and CMD invocations, and none work. They all fail with "no such file or directory". When I change the entry point to "/bin/sh" and launch the container interactively, I can see the file /usr/local/bin/shelltest.sh, and it has execute permissions 755, so I'm at a loss to explain why this isn't working. Here's what the file looks like in the container when the entry point is set to "ls -l /usr/local/bin/shelltest.sh":

ENTRYPOINT ["ls", "-l", "/usr/local/bin/shelltest.sh"]

d:\Dev\Docker\shelltest>docker run shelltest 
-rwxr-xr-x 1 root root 32 Oct 29 16:32 /usr/local/bin/shelltest.sh

What am I missing?

Here are some things I've tried:

ENTRYPOINT ["/usr/local/bin/shelltest.sh"]

d:\Dev\Docker\shelltest>docker run shelltest
standard_init_linux.go:185: exec user process caused "no such file or directory"


ENTRYPOINT ["shelltest.sh"]

d:\Dev\Docker\shelltest>docker run shelltest
standard_init_linux.go:185: exec user process caused "no such file or directory"


CMD ["/usr/local/bin/shelltest.sh"]

d:\Dev\Docker\shelltest>docker run shelltest
standard_init_linux.go:185: exec user process caused "no such file or directory"

Upvotes: 4

Views: 1192

Answers (1)

Mr. bug
Mr. bug

Reputation: 377

Sometimes if you write your shell scripts in windows you get execution errors like that, try using dos2unix shelltest.sh or saving it as a Unix file, no DOS. If you can't do it manually (using notepad++, atom or sublime) try this link this link

Upvotes: 3

Related Questions