Solution to the problem that docker cannot delete the container: 1. Find the mounting location and then cancel the mounting; 2. Execute "#cat /proc/mounts |grep "docker" |grep "caf8ef20f3c1""; 3. , execute the deletion of the docker directory; 4. Delete the container service.
The operating environment of this article: ubuntu 18.04 system, Docker version 20.10.11, Dell G3 computer.
docker What should I do if I cannot delete the container?
Handling the problem of being unable to stop or delete the container service in Docker:
Preface
A developer classmate gave me feedback today that there is a container The service cannot be operated by stop, rm (docker rm -f) and kill, which means that the container service cannot be terminated~
Operation steps
(1) Perform deletion The command cannot delete the docker directory:
# ll /var/lib/docker/containers | grep caf8ef20f3c1 # cd /var/lib/docker/containers # rm -rf caf8ef20f3c1c78f03a5844ee23abc1d7e44246f242292040f1ef288899d0cb8
At this time we will receive an error like this:
rm: 无法删除"/var/lib/docker/containers/caf8ef20f3c1c78f03a5844ee23abc1d7e44246f242292040f1ef288899d0cb8/secrets": 设备或资源忙 无法删除"/var/lib/docker/containers/caf8ef20f3c1c78f03a5844ee23abc1d7e44246f242292040f1ef288899d0cb8/shm": 设备或资源忙
(2) From the error above, we can see that the "secrets" and "shm" shared mounts It cannot be deleted due to the mounting. First find the mounting location, then cancel the mounting, and then delete:
# cat /proc/mounts |grep "docker" |grep "caf8ef20f3c1"
(3) Cancel the mounting:
# umount /data/sys/var/docker/containers/caf8ef20f3c1c78f03a5844ee23abc1d7e44246f242292040f1ef288899d0cb8/secrets # umount /data/sys/var/docker/containers/caf8ef20f3c1c78f03a5844ee23abc1d7e44246f242292040f1ef288899d0cb8/shm
(4) View again:
# cat /proc/mounts |grep "docker" |grep "caf8ef20f3c1" //已经没有啦
(5) Now delete the docker directory:
# cd /var/lib/docker/containers # rm -rf caf8ef20f3c1c78f03a5844ee23abc1d7e44246f242292040f1ef288899d0cb8
(6) Delete the container service
Now we use rm or kill to delete the container service:
# docker rm -f caf8ef20f3c1c 或 # docker kill --signal=SIGINT caf8ef20f3c1
If a hang occurs after running the above command, please restart the docker service:
# systemctl restart docker
After completing the above steps, the problem will basically be solved~
Recommended Study: "Docker Video Tutorial"
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!