Issue


Dead container cannot be deleted.

Solution


Method 1

If you see the error message something like this: 

Error response from daemon: Cannot destroy container elated_wozniak: Driver devicemapper failed to remove root filesystem 656cfd09aee399c8ae8c8d3e735fe48d70be6672773616e15579c8de18e2a3b3: Device is Busy

Restart:

$ umount /var/lib/docker/devicemapper/mnt/656cfd09aee399c8ae8c8d3e735fe48d70be6672773616e15579c8de18e2a3b3
CODE

Method 2

You can delete dead containers with the command:

$ docker rm $(docker ps --all -q -f status=dead)
CODE

Method 3

Error:

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
  1. Check what other processes also use docker resources:

    $ grep docker /proc/*/mountinfo
    CODE
  2. Find the process, that will output something like the following, where the figure after /proc/ equals pid:

    /proc/10001/mountinfo:179...
    /proc/10002/mountinfo:149...
    /proc/12345/mountinfo:159 149 0:36 / /var/lib/docker/overlay/...
    CODE
  3. Check the process name above pid:

    $ ps -p 10001 -o comm=
    dockerd
    $ ps -p 10002 -o comm=
    docker-containe
    $ ps -p 12345 -o comm=
    nginx   <<<-- This is suspicious!!!
    CODE
  4. Nginx with pid 12345 also uses /var/lib/docker/overlay/... so we cannot delete the associated container and get the error  device or resource busy. 

  5. Stop Nginx:

    $ service nginx stop
    CODE
  6. Delete the container:

    $ docker rm <container-id>
    CODE
  7. Start the process:

    $ service nginx start
    CODE

We recommend that you restart the system if there are many processes.