Docker之rm: cannot remove ‘bkce/cicdkit/docker/lib/docker/overlay2’: Device or resource busy

[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 ? !

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值