【发布时间】:2022-04-26 21:42:05
【问题描述】:
我有一个使用以下 CMD 构建的 Docker 映像
# Dockerfile
...
CMD ["nginx", "-g", "daemon off;"]
当我的任务定义不包含entryPoint 或command 时,任务成功进入运行状态。
{
"containerDefinitions": [
{
"image": "<myregistry>/<image>",
...
}
]
}
我需要在此容器的某些实例中运行代理,因此我使用entrypoint 来执行此任务来运行我的代理。问题是当我在任务定义中添加entryPoint 参数时,容器启动并立即停止。
这就是我添加entryPoint的方法:
{
"containerDefinitions": [
{
"image": "<myregistry>/<image>",
...
"entryPoint": [
"custom-entry-point.sh"
],
}
]
}
这是custom-entry-point.sh的内容:
#!/bin/bash
/myagent &
echo "CMD is: $@"
exec "$@"
为了证实我怀疑 CMD 已被删除,日志仅显示:
CMD is:
如果我使用 command 参数将 Dockerfile 中的 CMD 数组添加到任务定义中,它可以正常工作并且任务开始:
{
"containerDefinitions": [
{
"image": "<myregistry>/<image>",
...
"entryPoint": [
"custom-entry-point.sh"
],
"command": [
"nginx",
"-g",
"daemon off;"
}
]
}
日志显示预期:
CMD is: nginx -g daemon off;
我有许多带有CMD 各种迭代的 docker 图像,我不想将它们复制到我的任务定义中。似乎只在任务定义中添加 only entryPoint 不应使用空值覆盖 docker 映像的 CMD。
希望一些 ECS / fargate 专家可以帮助阐明前进的道路。
【问题讨论】:
-
你找到答案了吗?