docker技巧

docker rm容器报错Error response from daemon: driver “overlay” failed to remove root filesystem for xxx device or resource busy 解决办法

docker删除容器报错信息:
[root@moneyslow.com ~]# docker rm -f 6105a0e6d7dc
Error response from daemon: driver “overlay” failed to remove root filesystem for 6105a0e6d7dc3e1c9f7f68ed273dcc22e9b954e6f0ddbd58026da6ee839a0c2d: remove /var/lib/docker/overlay/f9614e02b2c67bae1d6df46d5ca470a6468c2597ed7be82134ac9df3a8f3d5ce/merged: device or resource busy

我就呵呵了,设备忙。思路,找谁在用这个目录,
用 f9614e02b2c67bae1d6df46d5ca470a6468c2597ed7be82134ac9df3a8f3d5ce 这段找找系统里mount信息里使用这个玩意的进程:

[root@moneyslow.com ~]# grep 5ca470a6468c2597ed7be82134ac9df3a8f3d5ce /proc/*/mountinfo
/proc/15877/mountinfo:171 167 0:38 / /var/lib/docker/overlay/f9614e02b2c67bae1d6df46d5ca470a6468c2597ed7be82134ac9df3a8f3d5ce/merged rw,relatime shared:113 – overlay overlay rw,lowerdir=/var/lib/docker/overlay/3e608cff644197e9909e640a5e856618ef44d38b4ef804d3927a91377b23d50f/root,upperdir=/var/lib/docker/overlay/f9614e02b2c67bae1d6df46d5ca470a6468c2597ed7be82134ac9df3a8f3d5ce/upper,workdir=/var/lib/docker/overlay/f9614e02b2c67bae1d6df46d5ca470a6468c2597ed7be82134ac9df3a8f3d5ce/work

以上看到没有,proc后面跟的就是进程号 15877,看看是什么东西:

[root@moneyslow.com ~]# ps -ef|grep 15877
ntp 15877 1 0 2018 ? 00:00:47 /usr/sbin/ntpd -u ntp:ntp -g
root 31928 31032 0 16:18 pts/5 00:00:00 grep –color=auto 15877

我就草了,是ntp,暂时没时间研究这个,停它:
[root@moneyslow.com ~]# systemctl stop ntpd.service
[root@moneyslow.com ~]# ps -ef|grep 15877
root 32110 31032 0 16:20 pts/5 00:00:00 grep –color=auto 15877

[root@moneyslow.com ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6105a0e6d7dc docker.moneyslow.com/zhuanqian/wohahaha:base “docker-php-entrypoi…” 12 months ago Removal In Progress hqreceive
751f97d133f9 docker.moneyslow.com/mysql/mysql:v5.6.38 “docker-entrypoint.s…” 12 months ago Up 9 minutes 0.0.0.0:3306->3306/tcp mysql3306_hq

再试试,成功删除:
[root@moneyslow.com ~]# docker rm 6105a0e6d7dc
6105a0e6d7dc

参考:https://stackoverflow.com/questions/30794108/docker-cannot-remove-dead-container