Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Why?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading