How to correctly quote task command / entrypoint ?

0

I am trying to replicate the advice for running Nginx and Certbot in containers in an Amazon ECS environment. The advice I have been following can be found https://medium.com/@pentacent/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71.

This has been great but I am struggling with the last step which is to ensure the certificates are updated in the future. For example the recommended command for Nginx is:

command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g "daemon off;"'"

On a local container this worked but ECS Neds this in the string array format so I used the following command (which worked locally):

command: \["/bin/sh","-c","while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g "daemon off;""]

I added the same to the ACS console. However, the task fails to start and in the output I get:

/bin/sh: 1: wait: Illegal number: 1{!}
nginx: invalid option: "off"
/bin/sh: 1: ": not found

The command in the Task JSON looks like this:

"command": \[
"/bin/sh",
"-c",
"while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g "daemon off;""
],

It looks like this is failing to interpret correctly but I am not sure how I should be quoting (or escaping) this for it to work correctly?

Edited by: JSDev on Sep 22, 2020 3:00 PM

Edited by: JSDev on Sep 22, 2020 3:00 PM

Edited by: JSDev on Sep 22, 2020 3:02 PM

Edited by: JSDev on Sep 22, 2020 3:03 PM

Edited by: JSDev on Sep 22, 2020 3:03 PM

Edited by: JSDev on Sep 22, 2020 3:22 PM

JSDev
gefragt vor 4 Jahren815 Aufrufe
1 Antwort
0

It turns out the correct stanza needed in the console was:

/bin/sh,-c,while :; do sleep 6h & wait $!; nginx -s reload; done & nginx -g 'daemon off'

This let the JSON generator wrap everything in ".." quotes and it worked. Also in this environment I had to use $! for the child PID, not the $${!} needed for the docker-compose version.

JSDev
beantwortet vor 4 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen