Home Ask Login Register

Developers Planet

Your answer is one click away!

Leon February 2016

Basic Dockerfile not running CMD command

I have a simple Dockerfile that doesnt seem to be executing the CMD command.

FROM nginx

#Expose port 80

#Start nginx server
#RUN service nginx start

COPY startup_nginx.sh /startup_nginx.sh
RUN chmod +x /startup_nginx.sh

#CMD ["/usr/bin/wc","--help"]
CMD ['/startup_nginx.sh']

What could be the problem?


Leon February 2016

It turns out that I need double quotes instead of single like this.

CMD ["/startup_nginx.sh"]

Note This is not explicit in the docs and seems like something basic that should be spelled somewhere as there are no error messages. It fails silently which makes it extremely hard to debug as the startup script is what is needed to create a running process so the container doesnt exit.

VonC February 2016

Note: there is issue 5701 requesting for making a docker build error when single quotes are used in JSON expressions like ENTRYPOINT or CMD.

PR 8486 is supposed to resolve this, but it only add a test case, not the actual error itself.
It does explain the problem though:

This testcase is supposed to generate an error because the JSON array we're passing in on the CMD uses single quotes instead of double quotes (per the JSON spec).
This means we interpret it as a "string" instead of "JSON array" and pass it on to "sh -c" and it should barf on it

Post Status

Asked in February 2016
Viewed 2,723 times
Voted 10
Answered 2 times


Leave an answer

Quote of the day: live life