docker深刻2-容器刪除操做失敗html
2017/9/26node
一、報錯 Error response from daemon: driver "overlay" failed to remove root filesystem for xxx: remove /var/lib/docker/overlay/xxx/merged: device or resource busy 緣由:被其餘容器佔用了資源。 分析方法:查找 /proc/*/mountinfo 來確認是哪一個 pid 在 mount 資源。 解決辦法:重啓監控類型的 service 二、版本信息 [root@test_node_02 ~]# docker info Server Version: 17.06.0-ce Storage Driver: overlay Backing Filesystem: extfs Supports d_type: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog Swarm: active Kernel Version: 3.10.0-514.21.1.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 1.797GiB Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Experimental: false 三、分析過程 1)嘗試刪除一個處於 dead 狀態的容器: [root@test_node_02 ~]# docker rm -f $(docker ps -a --filter status=dead -q |head -n 1) Error response from daemon: driver "overlay" failed to remove root filesystem for 808acab2716420275cdb135ab964071cfc33406a34481354127635d3a282fa31: remove /var/lib/docker/overlay/88440438ea95b47e7459049fd765b51282afee4ad974107b0bf96d08d9c7763e/merged: device or resource busy 2)查找 /proc/*/mountinfo 來確認是哪一個 pid 在 mount 資源: [root@test_node_02 ~]# grep -l --color `docker ps -a --filter status=dead -q |head -n 1` /proc/*/mountinfo 3)查找 pid 確認進程的用途 [root@test_node_02 ~]# ps -f 7360 UID PID PPID C STIME TTY STAT TIME CMD root 7360 7344 1 Aug16 ? Ssl 73:57 /usr/bin/cadvisor -logtostderr 4)還能夠驗證,使用的不是同一個 mount namespace [root@test_node_02 ~]# ls -l /proc/$(cat /var/run/docker.pid)/ns/mnt /proc/7360/ns/mnt lrwxrwxrwx 1 root root 0 Aug 21 15:55 /proc/11460/ns/mnt -> mnt:[4026531840] lrwxrwxrwx 1 root root 0 Aug 21 15:55 /proc/7360/ns/mnt -> mnt:[4026532279] [root@test_node_02 ~]# 5)嘗試重啓 cadvisor 服務: [root@test_node_01 ~]# docker service ls |grep cadvisor 5f001c9293cf cadvisor global 3/3 google/cadvisor:latest [root@test_node_01 ~]# docker service update --force cadvisor [root@test_node_01 ~]# 6)再次刪除: [root@test_node_02 ~]# docker rm -f $(docker ps -a --filter status=dead -q |head -n 1) 808acab27164 [root@test_node_02 ~]# 符合預期。 四、結論 有其餘的容器或服務,掛載的捲包含了 '/var/lib/docker' or '/' 後,將致使資源佔用,從而引起異常。 如何繞過:找到這樣的容器或者服務,重啓,而後再重試刪除操做 如何解決:未知,待跟進。 來自: https://github.com/moby/moby/issues/34652#issuecomment-325352551 cpuguy83 commented 7 days ago Let's close this because this is exactly the same as #22260 which is still open. Thanks! In order to fix your current situation, the easiest thing is a reboot. The issue is the mount has leaked into another mount namespace... likely another container by bind-mounting /var/lib/docker (or one of it's parents) into a container. 所以,目前的結論是:掛載點泄漏,暫無最終的解決方案。 20170926更新: https://github.com/moby/moby/issues/22260#issuecomment-329322860 Vanuan commented 12 days ago edited Looks like RHEL/CentOS 7.4 has a "detached mount" option: https://bugzilla.redhat.com/show_bug.cgi?id=1441737 It is "0" by default. Does it mean we should set it to "1"? Or does a recent docker yum package has this option included? RHEL 7.4 kernel has introduced a new sysctl knob to control kernel behavior. This is called /proc/sys/fs/may_detach_mounts. This knob is set to value 0 by default. Container run times (docker and others) need the new behavior and want it to be set to 1. So modify runc package to drop a file say /usr/lib/sysctl.d/99-docker.conf. Contents of this file can be say following. fs.may_detach_mounts=1 https://github.com/moby/moby/issues/22260#issuecomment-329716346 owhen commented 11 days ago @antoinetran CentOS 7.4 is available. https://lists.centos.org/pipermail/centos-announce/2017-September/022532.html Check out some mirrors: http://mirror.wiuwiu.de/centos/7.4.1708/ https://github.com/moby/moby/issues/22260#issuecomment-330214623 cpuguy83 commented 8 days ago fs.may_detach_mounts=1 should resolve this on 7.4 @xdexter https://github.com/moby/moby/issues/22260#issuecomment-330217256 xdexter commented 8 days ago Hello, The option fs.may_detach_mounts=1 fixed my problem in CentOS 7.4. Regards https://github.com/moby/moby/issues/22260#issuecomment-330222776 cpuguy83 commented 8 days ago Working on a patch to make Docker set this param on startup. https://github.com/moby/moby/pull/34886 所以,目前的結論是:在 CentOS 7.4 能夠解決這個問題,待自行驗證。 ZYXW、參考 一、github https://github.com/moby/moby/issues/22260 https://github.com/moby/moby/issues/22260#issuecomment-323645024 二、docker: devicemapper fix for 「device or resource busy」 (EBUSY) http://blog.hashbangbash.com/2014/11/docker-devicemapper-fix-for-device-or-resource-busy-ebusy/