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
Change the entrypoint to:
When you interactively run
sh test.sh
, the shell breaks it into two words for you. The JSON-array form ofENTRYPOINT
andCMD
(and alsoRUN
) 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
However: you shouldn’t need the explicit
sh
at all. If the script is executable (as inchmod +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 runwithout directly saying
sh
anywhere.