docker - how do you disable auto-restart on a container?

后端 未结 4 1181
梦如初夏
梦如初夏 2020-11-29 15:58

I can enable auto-restart with --restart=always, but after I stop the container, how do I turn off that attribute?

I normally run a webserver and typica

相关标签:
4条回答
  • 2020-11-29 16:07

    Use the below to disable ALL auto-restarting (daemon) containers.

    docker update --restart=no $(docker ps -a -q)
    

    Use the following to disable restart a SINGLE container.

    docker update --restart=no the-container-you-want-to-disable-restart
    

    Rational:

    Docker provides restart policies to control whether your containers start automatically when they exit, or when Docker restarts. This is often very useful when Docker is running a key service.

    Notes

    If you are using docker-compose this might be useful to know.

    restart no is the default restart policy, and it does not restart a container under any circumstance. When always is specified, the container always restarts. The on-failure policy restarts a container if the exit code indicates an on-failure error.

    restart: "no"
    restart: always
    restart: on-failure
    restart: unless-stopped
    
    restart: always
    
    0 讨论(0)
  • 2020-11-29 16:14

    If you have a swarm restarting the containers, the swarm will restart any containers you stop or rm, irrespective of the restart option. That's a feature, not a bug.

    Make sure you are not running a service you forgot about:

    docker service ls
    

    Then, you can stop the service

    docker service rm <service id discovered with previous command>
    
    0 讨论(0)
  • 2020-11-29 16:30

    You can use the --restart=unless-stopped option, as @Shibashis mentioned, or update the restart policy (this requires docker 1.11 or newer);

    See the documentation for docker update and Docker restart policies.

    docker update --restart=no my-container
    

    that updates the restart-policy for an existing container (my-container)

    0 讨论(0)
  • 2020-11-29 16:30

    You can start your container with --restart=unless-stopped.

    0 讨论(0)
提交回复
热议问题