Cannot stop or restart a docker container
DockerDocker Problem Overview
When trying to stop or restart a docker container I'm getting the following error message:
$ docker restart 5ba0a86f36ea
Error response from daemon: Cannot restart container 5ba0a86f36ea: [2] Container does not exist: container destroyed
Error: failed to restart containers: [5ba0a86f36ea]
But when I run
$ docker logs -f 5ba0a86f36ea
I can see the logs, so obviously the container does exist. Any ideas?
Edit:
sorry, I forgot to mention this:
When I run docker ps -a
I see the container as up and running. However the application inside it is malfunctioning so I want to restart it, or just get a fresh version of that application online. But when I can't stop and remove the container, I also can't get a new application up and running, which would be listening to the same port.
Docker Solutions
Solution 1 - Docker
I couldn't locate boot2docker
in my machine. So, I came up with something that worked for me.
$ sudo systemctl restart docker.socket docker.service
$ docker rm -f <container id>
Check if it helps you as well.
Solution 2 - Docker
All the docker:
start | restart | stop | rm --force | kill
commands
may not work if the container is stuck. You can always restart the docker daemon. However, if you have other containers running, that may not be the option. What you can do is:
ps aux | grep <<container id>> | awk '{print $1 $2}'
The output contains:
<<user>><<process id>>
Then kill the process associated with the container like so:
sudo kill -9 <<process id from above command>>
That will kill the container and you can start a new container with the right image.
Solution 3 - Docker
That looks like docker/docker/issues/12738, seen with docker 1.6 or 1.7:
Some container fail to stop properly, and the restart
> We are seeing this issue a lot in our users hosts when they upgraded from 1.5.0 to 1.6.0.
After the upgrade, some containers cannot be stopped (giving 500 Server Error: Internal Server Error ("Cannot stop container xxxxx: [2] Container does not exist: container destroyed"
)) or forced destroyed (giving 500 Server Error: Internal Server Error ("Could not kill running container, cannot remove - [2] Container does not exist: container destroyed"
)).
The processes are still running on the host.
> Sometimes, it works after restarting the docker daemon.
There are some workarounds:
> I've tried all remote API calls for that unkillable container and here are results:
> - json
, stats
, changes
, top
, logs
returned valid responses
stop
,pause
,wait
,kill
reported 404 (!)
> After I finished with remote API, I double-checked docker ps
(the container was still there), but then I retried docker kill and it worked! The container got killed and I could remove it.
Or:
> What worked was to restart boot2docker
on my host. Then docker rm -f
$ boot2docker stop
$ boot2docker start
$ docker rm -f 1f061139ba04
Solution 4 - Docker
Worth knowing:
If you are running an ENTRYPOINT script ... the script will work with the shebang
#!/bin/bash -x
But will stop the container from stopping with
#!/bin/bash -xe
Solution 5 - Docker
Enjoy
sudo aa-remove-unknown
This is what worked for me.
Solution 6 - Docker
Check if there is any zombie process using "top" command.
docker ps | grep <<container name>>
Get the container id.
ps -ef | grep <<container id>>
ps -ef|grep defunct | grep java
And kill the container by Parent PID .
Solution 7 - Docker
For anyone on a Mac who has Docker Desktop installed. I was able to just click the tray icon and say Restart Docker
. Once it restarted was able to delete the containers.
Solution 8 - Docker
If you're on a Mac and try this via Terminal: Use killall Docker
to quit Docker.
Restart it in the Applications folder or with open /Applications/Docker.app
.
Subsequently you can run a docker rm <id>
for the concerned container.
Solution 9 - Docker
I had the same problem on a windows host machine and none of the other options here worked for me. I ended up just needing to delete the physical container folder, which was located here:
C:\ProgramData\Docker\containers\[container guid]
I had stopped the docker service first just to be safe and when I restarted it, the broken containers were now gone and I was able to create new ones. I suspect the same will work on a linux host machine, but I do not know where the container folders are kept on that OS.
Solution 10 - Docker
in my case, i couldn't delete container created with nomad jobs,
there's no output for the docker logs <ContainerID>
and, in general, it looks like frozen.
until now the solution is: sudo service docker restart
, may someone suggest better one?
Solution 11 - Docker
If you're on Ubuntu, make sure docker-compose isn't installed as snap. This will cause all kinds of random issues, including the above.
Remove the snap:
sudo snap remove docker-compose
And install manually from compose repository:
Solution 12 - Docker
i forgot that i had made the container start as a system service.
so if i stopped or killed the container, the service would bring it back.
if you are using systemctl, you can list all the running services with systemctl | grep running
and find the name of the service.
then use
sudo systemctl disable <your_service_name>
to stop it.
Solution 13 - Docker
Sometimes this is caused by problem of the docker daemon. I solved the problem by restarting the docker service. On Linux:
systemctl restart docker
Solution 14 - Docker
In my case, docker rm $(docker ps -aq)
works for me.