简体   繁体   English

在 Amazon ECS 任务中指定入口点时出现问题

[英]Problem specifying entrypoint in Amazon ECS Task

I am trying to replicate the advice for running Nginx and Certbot in containers in an Amazon ECS environment.我正在尝试复制在 Amazon ECS 环境中的容器中运行 Nginx 和 Certbot 的建议。 The advice I have been following can be found here .我一直遵循的建议可以在这里找到。 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:例如,Nginx 的推荐命令是:

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 needs this in the string array format so I used the following command (which worked locally):在本地容器上这有效,但 ECS 需要字符串数组格式,所以我使用了以下命令(在本地有效):

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

I added the same to the ECS console.我将其添加到 ECS 控制台。 However, the task fails to start and in the output I get:但是,任务无法启动,在 output 中我得到:

/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:任务 JSON 中的命令如下所示:

"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?看起来这无法正确解释,但我不确定我应该如何引用(或转义)它才能正常工作?

Can you give "command my version" a try?你能试试“命令我的版本”吗? I believe you have a problem because you replaced the ' by "我相信您有问题,因为您将 ' 替换为 "

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

Finally found the magic combination that satisfied both JSON and sh quoting needs... and fixed a script error on the way.终于找到了满足JSONsh引用需求的神奇组合......并修复了途中的脚本错误。 The final stance was to enter this in the ECS console:最后的姿态是在ECS控制台输入这个:

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

This resulted in JSON that looks like:这导致JSON看起来像:

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

For some reason in the ECS environment I was able to use the much more direct reference to the child PID $!出于某种原因,在 ECS 环境中,我能够更直接地引用子 PID $! rather than the more obscure SS{!} needed for the docker-compose world.而不是docker-compose世界所需的更晦涩的SS{!}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM