skip to Main Content

I made a small container that runs a single shell script.
Its Dockerfile is as follows:

FROM centos:centos7.9.2009

RUN mkdir -p /var/lib/test
COPY ./ /var/lib/test/
RUN yum -y localinstall /var/lib/test/*.rpm

ENTRYPOINT ["sh /var/lib/test/test.sh"]

However, when I run the image, it returns the error:

#docker run -it test:1.0
/usr/bin/docker-current: Error response from daemon: oci runtime error: container_linux.go:290: starting container process caused "exec: "sh /var/lib/test/test.sh": stat sh /var/lib/test/test.sh: no such file or directory".

The script file definitely exists as I can replace its entrypoint with bash and manually execute it:

# docker run -it --entrypoint bash test:1.0
[root@e9361c3e67fa /]# sh /var/lib/test/test.sh
Shell script starts...

I read similar posts and confirmed that the permission of the script is correct, the return codes inside it were all LF.

And the shell script is really simple:

#!/bin/bash
echo "Test"
exit 0

What else can cause this problem?

2

Answers


  1. Change the entrypoint to:

    ENTRYPOINT ["/bin/bash", "-c", "/var/lib/test/test.sh"]
    
    Login or Signup to reply.
  2. When you interactively run sh test.sh, the shell breaks it into two words for you. The JSON-array form of ENTRYPOINT and CMD (and also RUN) requires you to explicitly break up the words yourself, though. As you have it written in a single array entry is the same as writing a single word in quotes 'sh test.sh' at a shell prompt.

    The most expedient answer is to break this into two words

    ENTRYPOINT ["sh", "/var/lib/test/test.sh"]
    

    However: you shouldn’t need the explicit sh at all. If the script is executable (as in chmod +x) and begins with the line #!/bin/sh, then the system will be able to figure out that it’s a standard Bourne shell script. You should be able to just run

    ENTRYPOINT ["/var/lib/test/test.sh"]
    # (or CMD ["/var/lib/test/test.sh"])
    

    without directly saying sh anywhere.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search