Docker - Cannot remove dead container

后端 未结 20 1510
清歌不尽
清歌不尽 2020-12-22 16:28

I am unable to remove the dead container, it appears again after i restart the Docker service.

docker ps -a
CONTAINER ID         STATUS          
11667ef1623         


        
相关标签:
20条回答
  • 2020-12-22 17:15

    Try, It worked for me:

    $ docker ps -a
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
    4f13b53be9dd        5b0bbf1173ea        "/opt/app/netjet..."   5 months ago        Dead                                    appname_chess
    
    $ docker rm $(docker ps --all -q -f status=dead)
    Error response from daemon: driver "devicemapper" failed to remove root filesystem for 4f13b53be9ddef3e9ba281546aef1c544805282971f324291a1dc91b50eeb440: failed to remove device 487b4b73c58d19ef79201cf6d5fcd6b7316e612e99c14505a6bf24399cad9795-init: devicemapper: Error running DeleteDevice dm_task_run failed
    
    su
    cd /var/lib/docker/containers
    [root@localhost containers]#  ls -l
    total 0
    drwx------. 1 root root 312 Nov 17 08:58 4f13b53be9ddef3e9ba281546aef1c544805282971f324291a1dc91b50eeb440
    [root@localhost containers]# rm -rf 4f13b53be9ddef3e9ba281546aef1c544805282971f324291a1dc91b50eeb440
    systemctl restart docker
    
    0 讨论(0)
  • 2020-12-22 17:16

    for Windows:

    del D:\ProgramData\docker\containers\{CONTAINER ID}
    del D:\ProgramData\docker\windowsfilter\{CONTAINER ID}
    

    Then restart the Docker Desktop

    0 讨论(0)
  • 2020-12-22 17:17

    I got the same issue and both answers did not help.

    What helped for me is just creating the directories that are missing and them remove them:

    mkdir /var/lib/docker/devicemapper/mnt/656cfd09aee399c8ae8c8d3e735fe48d70be6672773616e15579c8de18e2a3b3
    mkdir /var/lib/docker/devicemapper/mnt/656cfd09aee399c8ae8c8d3e735fe48d70be6672773616e15579c8de18e2a3b3-init
    docker rm 656cfd09aee399c8ae8c8d3e735fe48d70be6672773616e15579c8de18e2a3b3
    
    0 讨论(0)
  • 2020-12-22 17:17

    Running on Centos7 & Docker 1.8.2, I was unable to use Zgr3doo's solution to umount by devicemapper ( I think the response I got was that the volume wasn't mounted/found. )

    I think I also had a similar thing happen with sk8terboi87 ツ 's answer: I believe the message was that the volumes couldn't be unmounted, and it listed the specific volumes that it tried to umount in order to delete the dead containers.

    What did work for me was stopping docker first, and then deleting the directories manually. I was able to determine which ones they were by the error output of previous command to delete all the dead containers.

    Apologies for the vague descriptions above. I found this SO question days after I handled the dead containers. .. However, I noticed a similar pattern today:

    $ sudo docker stop fervent_fermi; sudo docker rm fervent_fermi fervent_fermi
    Error response from daemon: Cannot destroy container fervent_fermi: Driver devicemapper failed to remove root filesystem a11bae452da3dd776354aae311da5be5ff70ac9ebf33d33b66a24c62c3ec7f35: Device is Busy
    Error: failed to remove containers: [fervent_fermi]
    
    $ sudo systemctl docker stop
    $ sudo rm -rf /var/lib/docker/devicemapper/mnt/a11bae452da3dd776354aae311da5be5ff70ac9ebf33d33b66a24c62c3ec7f35
    $
    

    I did notice, when using this approach that docker re-created the images with different names:

    a11bae452da3     trend_av_docker   "bash"   2 weeks ago    Dead    compassionate_ardinghelli
    

    This may have been due to the container being issued with restart=always, however, the container ID matches the ID of the container that previously used the volume that I force-deleted. There were no difficulties deleting this new container:

    $ sudo docker rm -v compassionate_ardinghelli
    compassionate_ardinghelli
    
    0 讨论(0)
  • 2020-12-22 17:18

    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

    0 讨论(0)
  • 2020-12-22 17:18

    Try kill it and then remove >:) i.e.
    docker kill $(docker ps -q)

    0 讨论(0)
提交回复
热议问题