考虑一个看起来像这样的简单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网络应用,运行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 - use
docker stack deploy to deploy to a swarm.
我没有部署到群组。
如果使用非零退出代码失败,如何自动重启容器?
答案 0 :(得分:0)
deploy
部分仅在部署到docker stack deploy
的群组时生效,docker-compose up
和docker-compose run
会忽略。
restart
部分仅在使用docker-compose up
和docker-compose run
时生效。
version: "3"
services:
api:
image: my-container:latest
command: ["gunicorn", "--bind", "0.0.0.0:8000", "wsgi:app"]
volumes:
- ./api:/api
restart: no|always|on-failure|unless-stopped