Docker devicemapper 存储 space

Docker devicemapper storage space

删除容器时出现 "no space left on device" 错误。

# docker rm orientdb1
Error response from daemon: Driver devicemapper failed to remove root filesystem ba18ea8014b6024eb738502612130244ff363b433f146102c64eb2eb0f3a321c: devmapper: Error saving transaction metadata: devmapper: Error creating metadata file: open /var/lib/docker/devicemapper/metadata/.tmp636968871: no space left on device

这是 "df -kh" 输出的一个片段。

Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  3.8T  3.8T   20K 100% /

这里是 "du -ksh " 输出的片段。这表明使用了 3.8TB。

3.8T    /var/lib/docker

这是 "docker info" 输出。

# docker info
Containers: 56
 Running: 8
 Paused: 0
 Stopped: 48
Images: 18
Server Version: 1.12.0
Storage Driver: devicemapper
 Pool Name: docker-253:0-1196768-pool
 Pool Blocksize: 65.54 kB
 Base Device Size: 10.74 GB
 Backing Filesystem: xfs
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 24.51 GB
 Data Space Total: 107.4 GB
 Data Space Available: 20.48 kB
 Metadata Space Used: 29.18 MB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 20.48 kB
 Thin Pool Minimum Free Space: 10.74 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Deferred Deletion Enabled: false
 Deferred Deleted Device Count: 0
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 WARNING: Usage of loopback devices is strongly discouraged for 
 production use. Use `--storage-opt dm.thinpooldev` to specify a custom 
 block storage device.
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
  Library Version: 1.02.107-RHEL7 (2016-06-09)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host overlay null
 Swarm: inactive
 Runtimes: runc
Default Runtime: runc
Security Options: seccomp
Kernel Version: 3.10.0-327.22.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 12
Total Memory: 251.7 GiB
Name: my-host1
ID: KTTY:PSTQ:YQSP:9KZJ:VSVU:DFUZ:CEMF:DYWQ:CA3I:6KUB:6J2J:D4NG
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: bridge-nf-call-ip6tables is disabled
Insecure Registries:
 127.0.0.0/8

想从以下内容中了解 3.8 TB 是如何计算的(来自 "docker info" 的片段)

 Data Space Used: 24.51 GB
 Data Space Total: 107.4 GB
 Data Space Available: 20.48 kB
 Metadata Space Used: 29.18 MB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 20.48 kB
 Thin Pool Minimum Free Space: 10.74 GB

另外,我怎样才能清理 /var/lib/docker 以获得一些免费的 space。

我相信磁盘 space 数字是用于环回驱动程序和 devicemapper 在环回模式下使用的文件 /var/lib/docker/devicemapper/devicemapper/data。

要清理 docker,您可以 运行 docker system prune 在较新的版本上。旧版本可以使用如下命令:

docker ps -aqf status=exited | xargs docker rm
docker images -qf dangling=true | xargs docker rmi

除此之外,您还需要遍历容器和图像以达到 docker stop、容器上的 docker rm 和图像上的 docker rmi

要添加到 BMitch 的答案中,您还可以使用 docker volume ls -f dangling=true | xargs docker volume rm

之类的方法删除悬空卷以释放 space