【问题标题】:ECS/Fargate container definition command argumentsECS/Fargate 容器定义命令参数
【发布时间】:2019-07-18 00:38:11
【问题描述】:

我们正在尝试在 AWS ECS 上启动一个 Fargate 容器。在容器定义中我们有

"command": [
        "/bin/bash",
        "-c",
        "\"envsubst < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'\""
      ]

我也试过了:

"command": [
        "/bin/bash",
        "-c",
        "envsubst < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
      ]

使用docker run,我们将成功使用:

docker run -p 8000:80 -e "VAR1=somevalue" -d nginx-sample:latest /bin/bash -c "envsubst < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"

在 Kubernetes 世界中(也可以):

 containers:
      env:
      - name: VAR1
        value: "somevalue"
      command: ["/bin/bash"]
      args: ["-c", "envsubst < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"]

到目前为止,我们无法在 AWS Fargate 中实现此功能。我不清楚我们应该如何以有效的方式传递参数。容器似乎在能够启动之前就退出了,但没有明显的日志消息,因此尚不完全清楚原因。我认为这是我在传递/bin/bash -c 的命令参数的方式上的语法有问题。

【问题讨论】:

    标签: bash docker amazon-ecs aws-fargate docker-run


    【解决方案1】:

    最后正确的语法(至少对我们来说很有效)是:

    "command": [
            "/bin/bash",
            "-c",
            "envsubst < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
          ],
    

    我们真正的问题实际上是我们定义了一个容器健康检查:

    "healthCheck": {
            "retries": 5,
            "command": [
              "CMD-SHELL",
              "curl --fail http://localhost/health || exit 1"
            ],
            "timeout": 10,
            "interval": 30,
            "startPeriod": 30
          },
    

    我们忘记验证curl 是否实际安装在容器内。我们理所当然地认为它会在那里,但在nginx:latest 图像中,它不是——我认为对于较小的尺寸和较小的攻击面作为利用向量是正确的。我们最终只是在我们的Dockerfile 中安装了 curl,之后一切都很好。

    【讨论】:

      【解决方案2】:

      试试这个方法

      "entryPoint": [
              "/bin/bash",
              "-c"
            ],
      "command": [
              "envsubst < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
            ],
      

      当我们不得不做这样的事情时,这对我们有用。

      在我们的例子中,我们使用entryPoint 来强制容器忽略base image 命令。然后在commandarry 中给了一个额外的命令。

      如果我不相信,ECS 使用基本映像 CMD(CMD ["nginx", "-g", "daemon off;"]) 并在此之上运行 command 数组中的任何内容。我只是在猜测这个;因为我无法理解为什么其他方式不起作用。

      【讨论】:

        猜你喜欢
        • 2019-05-20
        • 2022-10-01
        • 2019-10-29
        • 2020-11-02
        • 1970-01-01
        • 2020-08-05
        • 2019-03-21
        • 2020-11-23
        • 2020-04-30
        相关资源
        最近更新 更多