如何在 ECS 任务定义中放置多行命令

How to put multiline commands in ECS Task definition

我正在尝试 运行 docker 容器(ECS - Fargate)中的 django 应用程序

但是,我无法弄清楚如何在任务定义的 Command 部分中 运行 多个命令,目前它是这样配置的

但是我的容器一直在运行 STOPPING,我什至看不到 CloudWatch 中的日志

如何让它正确执行?非常感谢任何帮助

在你的情况下,我将通过使用 /bin/sh -c 来完成此操作,尽管入口点为:

/bin/sh -c "python manage.py ... <and the rest>"

官方AWS ECS中也是这样tutorial:

            "entryPoint": [
                "sh",
                "-c"
            ],
            "command": [
                "/bin/sh -c \"echo '<html> <head> <title>Amazon ECS Sample App</title> <style>body {margin-top: 40px; background-color: #333;} </style> </head><body> <div style=color:white;text-align:center> <h1>Amazon ECS Sample App</h1> <h2>Congratulations!</h2> <p>Your application is now running on a container in Amazon ECS.</p> </div></body></html>' >  /usr/local/apache2/htdocs/index.html && httpd-foreground\""
            ]

问题出在其中一项服务 rk-nginx

这是之前的nginx.conf

upstream gunicorn {
    # docker will automatically resolve this to the correct address
    # because we use the same name as the service: "django"
    server django:8000;
}

但是 django 关键字给我带来了问题(我认为这是 ecs 处理网络的一部分),我只是将其更改为

upstream gunicorn {
    server localhost:8000;
}

这对我有用 aws ecs run-task 命令。

{
  "command": [
    "bin/sh", "-c", "echo 'Hello' && echo ' alien ' && echo 'World'"
  ]
}

命令只需要拆分为 bin/sh-c,其余命令可以用 &&.

连接在一起