Dav*_*vid 5 bash amazon-ecs docker aws-fargate docker-run
我们正在尝试在 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;'\""
]
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
"command": [
"/bin/bash",
"-c",
"envsubst < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
]
Run Code Online (Sandbox Code Playgroud)
使用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;'"
Run Code Online (Sandbox Code Playgroud)
在 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;'"]
Run Code Online (Sandbox Code Playgroud)
到目前为止,我们还无法在 AWS Fargate 中实现此功能。我不清楚我们应该如何以有效的方式传递论点。容器似乎在启动之前就退出了,但没有明显的日志消息,因此尚不完全清楚原因。/bin/bash -c我认为这是我在传递命令参数的语法上做错的事情。
最后,正确的语法(至少是一种对我们来说效果很好的语法)是:
"command": [
"/bin/bash",
"-c",
"envsubst < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
],
Run Code Online (Sandbox Code Playgroud)
我们真正的问题实际上是我们定义了容器健康检查,如下所示:
"healthCheck": {
"retries": 5,
"command": [
"CMD-SHELL",
"curl --fail http://localhost/health || exit 1"
],
"timeout": 10,
"interval": 30,
"startPeriod": 30
},
Run Code Online (Sandbox Code Playgroud)
我们忘记验证它curl是否确实安装在容器内。我们理所当然地认为它会在那里,但在nginx:latest图像中,它不是——我认为正确的是,对于较小的尺寸和较小的攻击面作为漏洞利用向量。我们最终只是在我们的中安装了curl Dockerfile,之后一切都很好。
| 归档时间: |
|
| 查看次数: |
5729 次 |
| 最近记录: |