Docker-Compose重启策略 [英] Docker-Compose Restart Policy
问题描述
我看了看docker-compose的文档,发现第3版具有部署重启策略,但仅适用于群集。我尝试在服务上设置restart_policy,但出现此错误:
I looked thru the docs for docker-compose and I see that Version 3 has a deploy restart policy but it's only for swarm. I tried setting restart_policy on my service but got this error:
ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.web: 'restart_policy'
是否可以对在群集之外使用docker-compose创建的服务设置重启策略?
推荐答案
版本2使用 restart
关键字支持重新启动策略,如果不需要Swarm(您说不需要/想要),该版本应该可以正常工作。 。
Version 2 supports restart policies, using the restart
keyword, and should work fine for you if you don't need Swarm (which you said you don't need/want).
version: '2'
services:
web:
image: apache
restart: always
https://docs.docker.com/compose/compose-file/compose-file-v2/ #restart
复合格式版本3具有标准名为 restart_policy
的仪表,但据我所知,它仅在 deploy
的一部分中有效。仅在部署到Swarm时使用。所以版本3可能对您没有用。
Compose format version 3 has a parameter called restart_policy
, but so far as I can tell from documentation it is only valid as part of deploy
, which is only used when deploying to a Swarm. So version 3 is probably not useful in your case.
这篇关于Docker-Compose重启策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!