I run some containers with the option --restart always.
It works good, so good, that I have now difficulties to stop these containers now :)
I tried :
sudo docker stop container && sudo docker rm -f container
But the container still restarts.
The docker documentation explains the restart policies, but I didn't find anything to resolve this issue.
Your answer The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL. This will stop a running container. This would restart the container.
To stop one or more running Docker containers, you can use the docker stop command. The syntax is simple: $ docker stop [OPTIONS] CONTAINER [CONTAINER...] You can specify one or more containers to stop.
1 Answer. You could also use the command $ docker restart [ container_name ] , but a disclaimer , this command is for running containers and not stopped ones.
Restart policies will be used whenever a container stops running. Docker also looks at restart policies when the daemon starts up. You can use this mechanism to bring containers up with your host after reboots. no – This policy will never automatically start a container. This is the default policy for all containers created with docker run.
But the main difference between the two is that if you stop the containers with docker stop command and then restart the docker daemon, the container with always restart policy will start the container automatically but the container with unless-stopped policy won't be restarted. Let me show it with examples.
Docker allows us to use the Docker rm and Docker stop commands to remove or stop one or more containers. However, if you want to stop and remove all the containers simultaneously, you can combine sub-commands to list all containers with the Docker stop and remove commands.
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.
Just
sudo docker rm -f container
will kill the process if it is running and remove the container, in one step.
That said, I couldn't replicate the symptoms you described. If I run with --restart=always
, docker stop
will stop the process and it remains stopped.
I am using Docker version 1.3.1.
docker update --restart=no <container>
Many thanks for those who takes time to respond.
If you use docker directly, Bryan is right sudo docker rm -f container
is enough.
My problem was mainly that I use puppet to deploy docker images and run containers. I use this module and it creates entries in /etc/init for the upstart process manager.
I think, my problem whas that, some kind of incompatibilities between the process manager and docker.
In this situation, to halt a container, simply sudo stop docker-container
.
More informations on managing docker container run can be found on the docker website
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With