Docker - Cannot remove dead container
Most likely, an error occurred when the daemon attempted to cleanup the container, and he is now stuck in this "zombie" state.
I'm afraid your only option here is to manually clean it up:
$ sudo rm -rf /var/lib/docker/<storage_driver>/11667ef16239.../
Where <storage_driver>
is the name of your driver (aufs
, overlay
, btrfs
, or devicemapper
).
You can also remove dead
containers with this command
docker rm $(docker ps --all -q -f status=dead)
But, I'm really not sure why & how the dead
containers are created. This error seems related https://github.com/typesafehub/mesos-spark-integration-tests/issues/34 whenever i get dead
containers
[Update] With Docker 1.13 update, we can easily remove both unwanted containers, dangling images
$ docker system df #will show used space, similar to the unix tool df
$ docker system prune # will remove all unused data.
Actually things changed slightly these days in order to get rid of those dead containers you may try to unmount those blocked filesystems to release them
So if you get message like this
Error response from daemon: Cannot destroy container elated_wozniak: Driver devicemapper failed to remove root filesystem 656cfd09aee399c8ae8c8d3e735fe48d70be6672773616e15579c8de18e2a3b3: Device is Busy
just run this
umount /var/lib/docker/devicemapper/mnt/656cfd09aee399c8ae8c8d3e735fe48d70be6672773616e15579c8de18e2a3b3
and you can normally remove container after that
I had the following error when removing a dead container (docker 17.06.1-ce on CentOS 7):
Error response from daemon: driver "overlay" failed to remove root filesystem for <some-id>:
remove /var/lib/docker/overlay/<some-id>/merged: device or resource busy
Here is how I fixed it:
1. Check which other processes are also using docker resources
$ grep docker /proc/*/mountinfo
which outputs something like this, where the number after /proc/
is the pid
:
/proc/10001/mountinfo:179...
/proc/10002/mountinfo:149...
/proc/12345/mountinfo:159 149 0:36 / /var/lib/docker/overlay/...
2. Check the process name of the above pid
$ ps -p 10001 -o comm=
dockerd
$ ps -p 10002 -o comm=
docker-containe
$ ps -p 12345 -o comm=
nginx <<<-- This is suspicious!!!
So, nginx
with pid 12345 seems to also be using /var/lib/docker/overlay/...
, which is why we cannot remove the related container and get the device or resource busy
error. (See here for a discussion on how nginx
shares the same mount namespace with docker containers thus prevents its deletion.)
3. Stop nginx
and then I can remove the container successfully.
$ sudo service nginx stop
$ docker rm <container-id>