![](/img/trans.png)
[英]Bash redirection in docker container failing when ran in ECS task on Amazon Linux 2 instances
[英]Problem specifying entrypoint in Amazon ECS Task
我正在嘗試復制在 Amazon ECS 環境中的容器中運行 Nginx 和 Certbot 的建議。 我一直遵循的建議可以在這里找到。 這很好,但我正在努力完成最后一步,以確保將來更新證書。 例如,Nginx 的推薦命令是:
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
在本地容器上這有效,但 ECS 需要字符串數組格式,所以我使用了以下命令(在本地有效):
command: ["/bin/sh","-c","while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\""]
我將其添加到 ECS 控制台。 但是,任務無法啟動,在 output 中我得到:
/bin/sh: 1: wait: Illegal number: 1{!}
nginx: invalid option: "off"
/bin/sh: 1: ": not found
任務 JSON 中的命令如下所示:
"command": [
"/bin/sh",
"-c",
"while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \\\"daemon off;\\\""
],
看起來這無法正確解釋,但我不確定我應該如何引用(或轉義)它才能正常工作?
你能試試“命令我的版本”嗎? 我相信您有問題,因為您將 ' 替換為 "
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;\"']
終於找到了滿足JSON
和sh
引用需求的神奇組合......並修復了途中的腳本錯誤。 最后的姿態是在ECS控制台輸入這個:
/bin/sh,-c,while :; do sleep 6h & wait $!; nginx -s reload; done & nginx -g 'daemon off'
這導致JSON
看起來像:
"command": [
"sh",
"-c",
"while :; do sleep 6h & wait $!; nginx -s reload; done & nginx -g 'daemon off;'"
],
出於某種原因,在 ECS 環境中,我能夠更直接地引用子 PID $!
而不是docker-compose
世界所需的更晦澀的SS{!}
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.