Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker container keeps restarting

Tags:

docker

I was trying rancher. I used the command: sudo docker run -d --restart=always -p 8080:8080 rancher/server to start run it. Then I stopped the container and removed it. But if I stop and restart the docker daemon or reboot my laptop, and lookup running containers using docker ps command, it will have rancher server running again. How do I stop/remove it completely and make sure it will not run again.

like image 419
codefire Avatar asked Aug 02 '16 08:08

codefire


People also ask

How do I stop the restarting container?

use sudo docker update --restart=no <container_id> to update --restart flag of the container. Now you can stop the container. Show activity on this post. You should be able to just use docker stop and then docker rm to make sure the container doesn't restart when the daemon restarts.

Why docker containers are restarted?

Use a restart policy Restart the container if it exits due to an error, which manifests as a non-zero exit code. Optionally, limit the number of times the Docker daemon attempts to restart the container using the :max-retries option.

How do I stop a docker container from running?

Note that pressing `Ctrl+C` when the terminal is attached to a container output causes the container to shut down.


1 Answers

Note: following issue 11008 and PR 15348 (commit fd8b25c, docker v1.11.2), you would avoid the issue with:

sudo docker run -d --restart=unless-stopped -p 8080:8080 rancher/server

In your current situation, thanks to PR 19116, you can use docker update to update the restart policy.

docker update --restart=unless-stopped <yourContainerID_or_Name>

Then stop your container, restart your docker daemon: it won't restart said container.


The OP codefire points to another reason in the comments:

When I first ran the start rancher server command, I didn't notice that it was being downloaded. So I may have retried that command a couple times.

That must be why the job kept on restarting even after stopping and removing containers that was started as rancher server.
After stopping and removing 8+ containers, it finally stopped

That is why I have aliases to quickly remove any stopped containers.

like image 149
VonC Avatar answered Sep 19 '22 11:09

VonC