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
asked 4 years ago807 views
1 Answer
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
answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions