Home > Enterprise >  Whs is my init.sh not found after succeful build?
Whs is my init.sh not found after succeful build?

Time:05-29

My Dockerfile

FROM alpine:latest

WORKDIR /usr/src/app
COPY ./init.sh /usr/src/app
RUN chmod  x init.sh
CMD ["sh","-c","init.sh"]

Build goes OK

 docker build . -t test
Sending build context to Docker daemon  3.072kB
Step 1/5 : FROM alpine:latest
 ---> e66264b98777
Step 2/5 : WORKDIR /usr/src/app
 ---> Running in 1ff4467854af
Removing intermediate container 1ff4467854af
 ---> 6b4f1fa4ca1c
Step 3/5 : COPY ./init.sh /usr/src/app
 ---> e61e55063baa
Step 4/5 : RUN chmod  x init.sh
 ---> Running in ae3724c0f595
Removing intermediate container ae3724c0f595
 ---> 3c2cd99a30b9
Step 5/5 : CMD ["sh","-c","init.sh"]
 ---> Running in 9df8c7d70e38
Removing intermediate container 9df8c7d70e38
 ---> bd9c9af6380d
Successfully built bd9c9af6380d
Successfully tagged test:latest

I got this

docker run -it test
sh: init.sh: not found

Why?

CodePudding user response:

Use ./init.sh to execute the script, provided that the shell script has a proper shebang like #!/bin/sh on the top:

FROM alpine:latest

WORKDIR /usr/src/app
COPY ./init.sh /usr/src/app
RUN chmod  x init.sh
CMD ["sh", "-c", "./init.sh"]

Note that it's actually not necessary, and can be shortened as CMD ./init.sh.

  • Related