【发布时间】:2018-04-02 07:35:50
【问题描述】:
考虑一个简单的docker-compose.yml,看起来像这样:
version: "3"
services:
api:
image: my-container:latest
command: ["gunicorn", "--bind", "0.0.0.0:8000", "wsgi:app"]
volumes:
- ./api:/api
api 服务是一个基于nginx 的 Python Flask Web 应用程序,运行gunicorn。有时,我会破坏 Flask 应用程序,gunicorn 会抛出一个非零退出代码并停止运行。然后我重建我所有的容器。我尝试了以下方法在失败后重新启动容器:
version: "3"
services:
api:
image: my-container:latest
command: ["gunicorn", "--bind", "0.0.0.0:8000", "wsgi:app"]
volumes:
- ./api:/api
deploy:
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 5
window: 60s
此配置忽略 deploy 配置选项并显示以下警告:WARNING: Some services (api) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - usedocker stack deployto deploy to a swarm. I'm not deploying to a swarm。
如何在失败且退出代码非零时自动重新启动容器?
【问题讨论】:
标签: python-3.x docker flask docker-compose gunicorn