4

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"
Alan
  • 3,715
  • 3
  • 39
  • 57

1 Answers1

3

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

Mr. bug
  • 366
  • 2
  • 11
  • The file already has "x" permission (755), I've added the file attributes output to my question. – Alan Oct 29 '17 at 17:40
  • 1
    Sometimes if you write your shell scripts in windows you get weird errors like that, try using `dos2unix shelltest.sh` or saving it as a Unix file, no DOS. If you don't have access to that kind of tools try [this link](http://newline.nadav.org) – Mr. bug Oct 29 '17 at 17:46
  • Please update your answer with this information, because that was the problem! I used Notepad++ to save the shell script with Unix line endings, and now the container executes successfully with the ENTRYPOINT set to that script path. Thank you! – Alan Oct 29 '17 at 17:57