Home  >  Article  >  Operation and Maintenance  >  What should I do if docker cannot delete the container?

What should I do if docker cannot delete the container?

王林
王林Original
2020-03-24 14:25:364345browse

What should I do if docker cannot delete the container?

Problem description:

The docker directory cannot be deleted by executing the delete command:

# ll /var/lib/docker/containers | grep caf8ef20f3c1
# cd /var/lib/docker/containers 
# rm -rf caf8ef20f3c1c78f03a5844ee23abc1d7e44246f242292040f1ef288899d0cb8

The error is reported as follows:

rm: 无法删除"/var/lib/docker/containers/caf8ef20f3c1c78f03a5844ee23abc1d7e44246f242292040f1ef288899d0cb8/secrets": 设备或资源忙
    无法删除"/var/lib/docker/containers/caf8ef20f3c1c78f03a5844ee23abc1d7e44246f242292040f1ef288899d0cb8/shm": 设备或资源忙

From the above error report, we can see that the "secrets" and "shm" shared mounts cannot be deleted.

(Recommended tutorial: docker tutorial)

Solution:

First find the mounting location, then cancel the mounting, and then delete:

# cat /proc/mounts |grep "docker" |grep "caf8ef20f3c1"

Unmount

# umount /data/sys/var/docker/containers/caf8ef20f3c1c78f03a5844ee23abc1d7e44246f242292040f1ef288899d0cb8/secrets
# umount /data/sys/var/docker/containers/caf8ef20f3c1c78f03a5844ee23abc1d7e44246f242292040f1ef288899d0cb8/shm

View again:

# cat /proc/mounts |grep "docker" |grep "caf8ef20f3c1"  //已经没有啦

Now execute the deletion of the docker directory:

# cd /var/lib/docker/containers 
# rm -rf caf8ef20f3c1c78f03a5844ee23abc1d7e44246f242292040f1ef288899d0cb8

Delete container service

Now we use rm or kill to delete the container service:

# docker rm -f caf8ef20f3c1c
或
# docker kill --signal=SIGINT  caf8ef20f3c1

If hang occurs after running the above command, please restart the docker service:

# systemctl restart docker

The above is the detailed content of What should I do if docker cannot delete the container?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn