[root@mysql57-1 data]# rm -rf bkce
rm: cannot remove ‘bkce/cicdkit/docker/lib/docker/overlay2’: Device or resource busy
[root@mysql57-1 data]# umount bkce/cicdkit/docker/lib/docker/overlay2
参考文章:
Google搜索Resolve docker netns issue: Device or resource busy
Also works for overlay : cannot remove ‘/var/lib/docker/overlay’
rm: cannot remove‘/var/run/docker/netns/default’: Device or resource busy
I encountered this issue with Docker version: 17.05.0-ce, build 89658be but seems to not be resolved in docker 17.06 at moment of writing as it’s related to this open issue: https://github.com/moby/moby/issues/22260.
Kernel Version: 3.10.0–514.el7.x86_64
Operating System: Red Hat Enterprise Linux Server 7.3 (Maipo)
OSType: linux
Architecture: x86_64
Context
I was trying to automate the lifecycle of a container from creation to deletion using a bash script. Someone could argue me that i could use an orchestrator as Kubernetes/Swarm but i want something more simpler because it’s just for test purpose and I did’nt want to manage orchestrator dependencies .
Well, It worked pretty fine until the day I have started to execute docker run commands with : -net=host . The purpose of fhis argument is to allwo the container to share the same NETWORK & UTS namespaces than host. It means that the container has the same hostame & share devices,iptables,etc … with the host.
How ?
My file docker_remove.sh was looking like :
echo “<<< Erasing docker rpm … >>>”
yum -y remove docker-engine docker-engine-selinux
echo “<<< Cleaning data rpm … >>>”
rm -rf /var/lib/docker
rm -rf /var/run/docker
After resolving the issue, it looks like:
echo “<<< Erasing docker rpm … >>>”
yum -y remove docker-engine docker-engine-selinux
umount /var/run/docker/netns/default
echo “<<< Cleaning data rpm … >>>”
rm -rf /var/lib/docker
rm -rf /var/run/docker
Why ?
Fisrtly, we have to check which process is using the resource. The command below will show you this PID process:
fuser /var/run/docker/netns/default
If you got the error : “fuser: command not found”, you have to install the package pmisc before:
yum -y install psmisc
Then, print mount information of this process:
grep docker /proc//mountinfo
You should notice a mount of /var/run/docker/netns/default to the root filesystem / . If you want more information about mountinfo , you can read this Linux manual page about /proc: http://man7.org/linux/man-pages/man5/proc.5.html
Solution
As seen above, we are just unmounting /var/run/docker/netns/default.
rm: cannot remove‘/var/lib/docker/overlay’: Device or resource busy
umount /var/lib/docker/overlay to resolve the issue.
Thanks for reading ? !