8

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;"?

Yaman Jain
  • 1,254
  • 11
  • 16
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
  • What if you use the JSON form of `CMD`? `CMD ["nginx", "-g", "\"daemon off;\""]` – larsks Sep 28 '17 at 13:06
  • Doesn't work either – Chris Stryczynski Sep 28 '17 at 13:08
  • This should work i guess `CMD ["nginx -g 'daemon off;'"]` – Tarun Lalwani Sep 28 '17 at 13:14
  • To explain what's happening: `/bin/sh -c nginx -g "daemon off;"` is running `nginx` as a script with `-g` in `$0` and `daemon off` in `$1`. But the script `nginx` doesn't look at either `$0` *or* `$1`. – Charles Duffy Sep 28 '17 at 13:15
  • The best option is *not to have* the `/bin/sh -c` at all. If you didn't have a shell, the rest of your argv would be correct exactly as it already is. – Charles Duffy Sep 28 '17 at 13:17
  • I have no idea where it's getting `/bin/sh -c` from – Chris Stryczynski Sep 28 '17 at 13:18
  • Could you provide a proper [mcve] so I could run the container myself? Could probably figure it out from there. – Charles Duffy Sep 28 '17 at 13:20
  • (mind you, one could come up with something that'll work right when appended to `sh -c` -- a simple do-nothing shim that passes the rest of the argv through might look like `[ "exec -a \"$0\" \"$@\"", "nginx", "nginx", "-g", "daemon off;" ]`, but it's silly to have it there). – Charles Duffy Sep 28 '17 at 13:24
  • (huh -- apparently `exec -a` is a bashism, so might need to make that `[ "exec \"$@\"", "nginx", "-g", "daemon off;" ]` -- means you give up control of `$0`, but so be it). – Charles Duffy Sep 28 '17 at 13:32
  • Does this answer your question? [CMD doesn't run after ENTRYPOINT in Dockerfile](https://stackoverflow.com/questions/54447913/cmd-doesnt-run-after-entrypoint-in-dockerfile) – ErikMD Sep 05 '20 at 20:15

1 Answers1

2

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.

Andrea Richiardi
  • 703
  • 6
  • 21