Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stop and delete a docker container launched with restart always option?

Tags:

docker

puppet

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.

like image 450
mperrin Avatar asked Dec 03 '14 22:12

mperrin


People also ask

How do I stop and restart a container?

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.

How do I stop an existing docker 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.

Can you restart a stopped docker container?

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.

What is restart policy in Docker?

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.

What is the difference between'always restart'and'unless stopped'in Docker?

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.

How to remove all containers in Docker?

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.

What is restartdocker and why do I need It?

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.


3 Answers

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.

like image 108
Bryan Avatar answered Oct 19 '22 00:10

Bryan


docker update --restart=no <container>

like image 41
Elijah Lynn Avatar answered Oct 19 '22 00:10

Elijah Lynn


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

like image 5
mperrin Avatar answered Oct 19 '22 00:10

mperrin