Docker-Compose Restart Policy

后端 未结 3 1075
长发绾君心
长发绾君心 2021-01-31 13:49

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 thi

3条回答
  •  眼角桃花
    2021-01-31 13:59

    Even if you're NOT in swarm mode, there is an option called --compatibility which will work with restart_policy, this will attempt to restart even if you're not deploying. The only glitch, is the sub-keys of 'delay' and 'window' will be ignored. Here is an example:

    version: '3.7'
    services:
      build:
        context: .
        dockerfile: Dockerfile
      container_name: example
      deploy:
        restart_policy:
          condition: on-failure
          max-attempts: 3
    

    run this command:

    docker-compose -f docker-compose.yml --compatability up
    

提交回复
热议问题