"CMD ['/home/user/script.sh']" in the docker file does not work with docker-compose

I have a Docker file that goes well with: docker build -t myfile . But when I try to run it with docker-compose - this gives me an error:

 web_1 | /bin/sh: 1: [/home/root/myproject/uwsgi.sh: not found myproject_web_1 exited with code 127 Gracefully stopping... (press Ctrl+C again to force) 

If I run this script manually, it works fine.

Dockerfile is as follows:

 FROM ubuntu:14.04 ADD ./myproject/ /home/root/myproject/ WORKDIR /home/root/myproject/ # Some other stuff... CMD ['/home/root/myproject/uwsgi.sh', 'start' ] 

Docker-compose.yml:

 web: build: . ports: - "8888:8888" links: - db db: image: mysql 

Why am I getting this error? Thanks.

+5
source share
2 answers

I simplified your example a bit

see https://github.com/BITPlan/docker-stackoverflowanswers/tree/master/33229581

and used:

Docker-compose.yml

 web: build: . ports: - "8888:8888" 

to find.

 . ./docker-compose.yml ./Dockerfile ./myproject 

build and run docker

 docker-compose build docker-compose run web 

and of course i get

 /bin/sh: 1: [/home/root/myproject/uwsgi.sh,: not found 

Assuming this is so, since uwsgi.sh is not in the myproject directory.

If I add uwsgi.sh with

 echo 'echo $0 is there and called with params $@ !' > myproject/uwsgi.sh chmod +x myproject/uwsgi.sh 

and test it with

 docker-compose run web /bin/bash ls cat uwsgi.sh ./uwsgi.sh start 

he behaves there as expected:

 root@9f06f8ff8c3b :/home/root/myproject# ls uwsgi.sh root@9f06f8ff8c3b :/home/root/myproject# cat uwsgi.sh echo $0 is there and called with params $@ ! root@9f06f8ff8c3b :/home/root/myproject# ./uwsgi.sh start ./uwsgi.sh is there and called with params start! root@9f06f8ff8c3b :/home/root/myproject# 

but for the website to launch docker I still get

 /bin/sh: 1: [/home/root/myproject/uwsgi.sh,: not found 

If I add a single space to the CMD Dockerfile line:

 CMD [ '/home/root/myproject/uwsgi.sh', 'start' ] 

result: / bin / sh: 1: [: /home/root/myproject/uwsgi.sh ,: unexpected statement

what brings us closer. As the next step, I leave the "start" parameter.

 CMD [ '/home/root/myproject/uwsgi.sh' ] 

now this leads to a lack of output ...

If I changed the CMD line to:

 CMD [ "/home/root/myproject/uwsgi.sh", "start" ] 

I get

  Cannot start container 0b9da138c43ef308ad70da4a7718cb96fbfdf6cda113e2ae0ce5e24de06f07cd: [8] System error: exec format error 

and now you can continue with Edison's approach:

I have not failed. I just found 10,000 ways that won't work. until you find

 CMD [ "/bin/bash", "/home/root/myproject/uwsgi.sh", "start" ] 

which brings you closer to the result:

  /home/root/myproject/uwsgi.sh is there and called with params start! 

CMD expects the executable to become the first parameter, for example.

https://docs.docker.com/compose/

It has

 CMD python app.py 

as an example. To run a shell script, you need a bash shell. See also fooobar.com/questions/1234080 / ...

+9
source

For others looking for help with this error message: I found that in my case it was caused by the absence of commas from the CMD line. Error Status:

 $ grep ^CMD Dockerfile CMD ["/bin/sh" "-c" "hostname"] $ docker run --rm -it hostname /bin/sh: 1: [/bin/sh: not found 

The commas were inserted correctly to fix the problem:

 $ grep ^CMD Dockerfile CMD ["/bin/sh", "-c", "hostname"] 
0
source

Source: https://habr.com/ru/post/1234077/


All Articles