Docker 创建这么多挂载并且不清理它们是否正常?

Docker 创建这么多挂载并且不清理它们是否正常?

我最近使用 overlay2 存储驱动程序配置了一台装有 Ubuntu 14.10 和 Docker CE 的服务器。运行几个容器后,我的df -h输出如下所示:

root@dev1:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        20G   12G  7.2G  62% /
devtmpfs        492M     0  492M   0% /dev
tmpfs           495M     0  495M   0% /dev/shm
tmpfs           495M  9.4M  486M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           495M     0  495M   0% /sys/fs/cgroup
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/c8a64b3d90888c734f0ac8b6854cabfdcf238e716f39080450a5abd85b5e371b/merged
shm              64M     0   64M   0% /var/lib/docker/containers/250094a88d3d6f3af5dbc3cf93636e382092e160c944f02c5008d07909f7a620/shm
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/9222282cf5f4274f50623b02c07e6863442cdb385117a3c9b1a98e52273af8ad/merged
shm              64M     0   64M   0% /var/lib/docker/containers/465d0f2a73f9005dbea7281b9fa0b553c3e99e49107b250172fade3764052e5a/shm
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/4f6340df52e9828bfc8d7c70a95ad6f8e7d9204a7a718ed4f72b9f6e91cc075a/merged
shm              64M     0   64M   0% /var/lib/docker/containers/46cd1080275a6a3f649330cfdff69e03ff8099fb31d81b736f3ffdc447c8a375/shm
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/a8ffd7344def30e0bde1caa80c0597c51663e3684b5e8deb4deb9ecf1395aea2/merged
shm              64M     0   64M   0% /var/lib/docker/containers/e40bd327b2ad3017d7350b1817de1d58cba42993eaa5dc4db5259a66fae29e44/shm
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/2520e792b3e86f6da1f8ece8b68cf5cea1f25c5da219fce579fc2a142d381af4/merged
shm              64M     0   64M   0% /var/lib/docker/containers/b1f626492cc5ae1ad241f521f11279705740261fbda71e38c134be61c3247830/shm
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/c4cb8bb4bb444272db2172c6409514d61a443ae26ce18b4b87b9e2813f60758e/merged
shm              64M     0   64M   0% /var/lib/docker/containers/6566daf418ccd3021410719c29aa202041769749ae027f3ee2f0db431613a547/shm
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/832ebb7c4641ef2cdb0708418110c400a63324cf2b4a489da2a4fcf565a00de1/merged
shm              64M     0   64M   0% /var/lib/docker/containers/8be7d0b8c449377fe51a5d581d438e07136e776ba67a434b5fe9338691afc811/shm
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/b48976d701f72245535d00035c31f67c06b163a6adf3cfa0aa65d7d9d635be76/merged
shm              64M     0   64M   0% /var/lib/docker/containers/1562126d1a41675f66ed4fa06885d81ef9f629ecb26905670d0a1ba547f34b37/shm
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/54a7a1647e89b61bb1f43a29a9ca20e082efa834c062c9c92da84ac301637eb0/merged
shm              64M     0   64M   0% /var/lib/docker/containers/2b069b9034223177fda4fd28a56b1d5efa32f1b9206e051c8b1e0f7a8bc18349/shm
tmpfs            99M     0   99M   0% /run/user/0
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/2bf5497b1743bf260cfb8e3619d8587a3b47f46633f3a8704ec1ef7a0725541a/merged
shm              64M     0   64M   0% /var/lib/docker/containers/8dcc013097a7a20f4c0b5833bb5b3d256876528c22d3484f849d52b55a6eb44a/shm
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/8a8a920c984ca0db9da745647900b3020fac173442bf268110ba06938be755b2/merged
shm              64M     0   64M   0% /var/lib/docker/containers/817a36bea3f79610b04d7ade9d16c122c30f7ff981996d17e556c95f16c5c102/shm
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/cd3e9dad0a7e6e9eaadf10816c4bd4e3fc0fb0134264c43aaac47da192c2933a/merged
shm              64M     0   64M   0% /var/lib/docker/containers/0af08a186eaa6d42c89af4728fb66b48ab32350fab0e19d68c7916c753255a45/shm
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/fd0e0505f9112f5ee239f06f7833694d37c9b473dc32bd1d367fb8042af75198/merged
shm              64M     0   64M   0% /var/lib/docker/containers/0270c05504523225206f37e85dca3915ca68def7a1e0aa148e5be0124a845b0e/shm
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/17f2a5db405350215cc432ff21f88acc699e8dbd879d1e3edb4bb40e0d9d09e2/merged
shm              64M     0   64M   0% /var/lib/docker/containers/0d9f0ce27b16363262cc9735734d3332c9e356c8aef1bf2a4a1ff05b085b231f/shm
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/44aae49e079d49db1447e09806ed8c697f25ac056d64325937c2d7e2cf9598f7/merged
shm              64M     0   64M   0% /var/lib/docker/containers/8108b6034e92ec0e1f7d90785c907148d5d2950be4b0573fc470c2587fb68337/shm
overlay          20G   12G  7.2G  62% /var/lib/docker/overlay2/b7da3582b33c6b8d72ff7af6295b653484e97877502abcf1f5b83dce25ac3c41/merged
shm              64M     0   64M   0% /var/lib/docker/containers/d707a2374f92f056b0ba1055a0055316f67a4300b73e0646204f8cf206f0de28/shm

即使我docker system prune清除了所有东西,这些挂载点还是没有消失。我似乎收集了越来越多的挂载点,但没有明显的方法可以摆脱它们。

这是正常/预期的行为吗?

docker info

Containers: 16
 Running: 14
 Paused: 0
 Stopped: 2
Images: 16
Server Version: 17.03.1-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 4ab9917febca54791c5f071a9d1f404867857fcc
runc version: 54296cf40ad8143b62dbcaa1d90e520a2136ddfe
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.15-x86_64-linode81
Operating System: Ubuntu 16.10
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 989 MiB
Name: dev1
ID: KWTP:NAOT:CGDG:HBCS:UOVG:H3XZ:IW7C:5EJA:IZI7:ROFZ:EHHU:TQNL
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Docker 安装脚本:

#!/bin/bash

# Install packages to allow apt to access a repository over https
sudo apt-get -y install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

# Add Dockers official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# Verify that the key fingerprint is 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
sudo apt-key fingerprint 0EBFCD88

# Set up the stable repository
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

# Update the apt package index.
sudo apt-get update

# Latest version of Docker
sudo apt-get -y install docker-ce

# Configure Docker FileSystem
mkdir -p /etc/systemd/system/docker.service.d
cat > /etc/systemd/system/docker.service.d/overlay2.conf <<EOF
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// --storage-driver=overlay2
EOF

# Add users to docker group
usermod -aG docker $(whoami)
usermod -aG docker $SUDO_USER

reboot

答案1

Containers: 16
 Running: 14
 Paused: 0
 Stopped: 2

这些挂载由正在运行的容器使用。您的信息显示您有 14 个正在运行的容器。prune 命令不会停止和删除正在运行的容器,因此预计不会清理这些挂载。要删除挂载,您需要停止并删除容器。使用:

docker container ls # list containers
docker container stop $container_id # stop the container
docker container rm $container_id # delete the container

--rm请注意,删除容器会删除所有日志、该容器的配置以及写入容器文件系统的任何内容。除非卷是匿名卷并且容器使用该选项启动,否则它不会删除卷。

答案2

我最近在 Ubuntu 20.04 上遇到了同样的问题,Docker v19.03.13。我搜索了 Docker 文档,发现这可能是由于他们引入了一种新类型的文件系统。你可以从中了解更多信息这里。我修复该问题的方法是编辑(如果尚不存在则创建)文件/etc/docker/daemon.json并添加以下几行:

{
  "storage-driver": "overlay"
}

然后使用以下命令重新启动docker:

sudo systemctl restart docker

相关内容