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

后端 未结 4 1190
梦如初夏
梦如初夏 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
    

提交回复
热议问题