Skip to content

Clarification on how to stop containers with --restart=always #10032

Closed
@hamiltont

Description

@hamiltont

What's the recommended way to terminate (permanently) containers that were started with --restart=always? If I kill them and then restart the daemon, they come back. If I kill them, remove that container and it's image, then they stay dead. Is this intended behavior? Is there an easier way to say "kill and don't restart"?

Activity

cpuguy83

cpuguy83 commented on Jan 11, 2015

@cpuguy83
Member

I'm not sure if it's intended behavior to restart a stopped container on daemon restart... but for sure docker rm <container> would be all that is needed, no need to remove the image.

88plug

88plug commented on Jun 21, 2017

@88plug

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

zrml

zrml commented on Aug 29, 2017

@zrml

The command above does not work for me with 17.06 CE

$ docker stop $(docker ps -a -q) &
[1] 10347
$ docker update --restart=no $(docker ps -a -q) &
[2] 10349
$ sudo systemctl restart docker95ca5f77f47f
e4729fa5a4eb
4145ccf79320
95ca5f77f47f
e4729fa5a4eb
4145ccf79320

[1]- Done docker stop $(docker ps -a -q)
[2]+ Done docker update --restart=no $(docker ps -a -q)

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4f5b57caaff3 quay.io/prometheus/prometheus:latest "/bin/prometheus -..." 11 seconds ago Up 5 seconds 9090/tcp monitoring_prometheus.1.92mo1fvdkzk19vszcqrlmlm5x

Any other suggestions please?
Thanks

cpuguy83

cpuguy83 commented on Aug 30, 2017

@cpuguy83
Member

@zrml If you call docker stop on a container, the container will not be restarted unless you restart the daemon (and it has --restart=always)

zrml

zrml commented on Sep 16, 2017

@zrml

@cpuguy83 sorry I'm late on this (too much traveling).
The container has --restart=always.
I am able to stop it, but shortly afterwards the daemon restarts it again.
The daemon does not have a --restart=always policy in /lib/systemd/system/docker.service.

Where is that flag for that container maintained? Can I get to it and reset it to --restart=no anywhere?

Thanks

thaJeztah

thaJeztah commented on Sep 16, 2017

@thaJeztah
Member

@zrml the --restart=always is set on docker run. If the container you're stopping is part of a swarm service though, docker will start a new container to replace it; that's expected

zrml

zrml commented on Sep 17, 2017

@zrml

@thaJeztah , you stand correct, it was set at docker run event. This is not part of a swarm. Thanks

vharsh

vharsh commented on Oct 31, 2017

@vharsh
thaJeztah

thaJeztah commented on Oct 31, 2017

@thaJeztah
Member

You can also update the restart policy of the container to prevent it from being restarted; see the documentation for docker update;

docker update --restart=no my-container
andrewb-ms

andrewb-ms commented on Jan 17, 2018

@andrewb-ms

The restart policy suggestion doesn't work. This seems really broken - there needs to be a "docker kill" command that shuts down the container and nukes it from the restart policy.

cpuguy83

cpuguy83 commented on Jan 17, 2018

@cpuguy83
Member

@andrewb-ms --restart=unless-stopped

lucsrods

lucsrods commented on Feb 7, 2018

@lucsrods

None of the solutions here worked for me, but after I verified the services (docker service ls) and removed them (docker service rm <service-id>), I was finally able to stop the containers.

I'm on Docker version 17.12.0-ce

thaJeztah

thaJeztah commented on Feb 7, 2018

@thaJeztah
Member

@Lucasar that's a different situation (not related to --restart=always), and the intended behaviour; if you start a swarm service, docker swarm reconciles the service's actual state with the desired state. That means that if you told it to start (e.g.) 5 instances of the service, and an instance of that service goes down (whatever the reason), Docker will create a new instance to replace the one that failed.

16 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ohcibi@gonvaled@hamiltont@cpuguy83@jessfraz

        Issue actions

          Clarification on how to stop containers with --restart=always · Issue #10032 · moby/moby