How to use quotes in Dockerfile CMD

Viewed 4988

I have the following in my Dockerfile:

ENTRYPOINT ["/bin/wait-for", "wordpress:9000", "--"]
CMD nginx -g "daemon off;"

Which results in:

nginx_1      | Attempting...
nginx_1      | Command: /bin/sh -c nginx -g "daemon off;"
nginx_1      | Attempting to execute command:
nginx_1      | /bin/sh -c nginx -g "daemon off;"
ayurved_nginx_1 exited with code 0

I'm guessing the issues is the quotes...

How can I make it execute /bin/wait-for wordpress:9000 -- nginx -g "daemon off;"?

1 Answers

I have had a similar problem when using CMD in the exec form, aka JSON array.

The TL;DR is that there seems to be a fallback mechanism that introduces /bin/sh when the CMD items cannot be parsed correctly.

I could not find the exact rules but I have examples:

ENTRYPOINT ["reflex"]
CMD ["-r", ".go$"]

$ docker inspect --format '{{.Config.Cmd}}' inventories_service_dev_1 
[-r .go$]
ENTRYPOINT ["reflex"]
CMD ["-r", "\.go$"]

$ docker inspect --format '{{.Config.Cmd}}' inventories_service_dev_1 
[/bin/sh -c ["-r", "\.go$"]]

Notice that \ in above.

Related