当前位置: 首页 > 工具软件 > thin > 使用案例 >

docker笔记11--docker build 报错 devmapper: Thin Pool空间不够解决方法

段干跃
2023-12-01

介绍

最近用docker构建镜像的时候,在中途出现 failed to create rwlayer: devmapper: Thin Poo … less than minimum required 报错。查阅资料发现是centos 上 docker启动的时候默认使用了devicemapper存储驱动,该驱动将docker目录挂载在 lvm 的分区上,该分区在使用过程中有一系列限制。随后将其调整为经典的 overlay2模式后恢复正常。

案例

docker build 报错

failed to create rwlayer: devmapper: Thin Pool has 158998 free data blocks which is less than minimum required 163840 free data blocks. Create more free space in thin pool or use dm.min_free_space option to change behavior

docker info 信息

# docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.6.3-docker)
  scan: Docker Scan (Docker Inc., v0.8.0)

Server:
 Containers: 1
  Running: 1
  Paused: 0
  Stopped: 0
 Images: 27
 Server Version: 20.10.9
 Storage Driver: devicemapper
  Pool Name: docker-253:16-13893683-pool
  Pool Blocksize: 65.54kB
  Base Device Size: 10.74GB
  Backing Filesystem: xfs
  Udev Sync Supported: true
  Data file: /dev/loop0
  Metadata file: /dev/loop1
  Data loop file: /data2/docker/devicemapper/devicemapper/data
  Metadata loop file: /data2/docker/devicemapper/devicemapper/metadata
  Data Space Used: 94.17GB
  Data Space Total: 107.4GB
  Data Space Available: 13.21GB
  Metadata Space Used: 179.4MB
  Metadata Space Total: 2.147GB
  Metadata Space Available: 1.968GB
  Thin Pool Minimum Free Space: 10.74GB
  Deferred Removal Enabled: true
  Deferred Deletion Enabled: true
  Deferred Deleted Device Count: 0
  Library Version: 1.02.170-RHEL7 (2020-03-24)
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 5b46e404f6b9f661a205e28d59c982d3634148f8
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 3.10.0-1160.42.2.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 7.375GiB
 Name: cnshc-srecicd-p01001
 ID: QXTX:FUSX:QWHJ:7E4H:MPOY:KBDI:DUD7:4PYO:SIDN:ZH73:C2GX:OXDO
 Docker Root Dir: /data2/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: the devicemapper storage-driver is deprecated, and will be removed in a future release.
WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use.
         Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.

由此可以发现, 当前可用 65.54158998/1024/1024=10420728.920000002=10.42GB小于 16384065.54/1024/1024=10738073.600000001=10.74GB, 无法满足docker 容器运行环境,所以才触发该问题。
其次,有 devicemapper storage-driver 被丢弃的提示,那么很明显可以不使用 devicemapper 的方式。

解决方法:
https://vinayakpandey-7997.medium.com/resolve-thin-pool-free-data-blocks-less-than-minimum-required-error-ffd9af38ba9d
修改docker 启动配置中的 Storage Driver 配置为overlay2
docker修改存储驱动为overlay2_qq_38286374的博客-CSDN博客_docker 修改overlay2

vim /etc/docker/daemon.json
{
"storage-driver": "overlay2"
}
重启docker 

注意事项

笔者查看docker的各种存储驱动介绍storagedriver/select-storage-driver,发现早期的 CentOS 和 RHEL由于内核版本不支持 overlay2,默认安装docker的时候为 devicemapper类型。
笔者的系统是centos7, 默认就是 devicemapper,笔者系统内核版本比较高,因此直接切换为 overlay2, 避免了 devicemapper 的限制。
若系统版本比较老,不便于升级,那么可以通过 direct-lvm mode 来配置docker的 storage-opts参数,从而提高其可用性。

说明

如何选择Docker存储驱动程序—overlay2、aufs、devicemapper、btrfs和zfs存储驱动
Use the Device Mapper storage driver
Docker 存储空间设置
Linux device mapper
LVM精简卷(Thinly-Provisioned Logical Volumes)
The Linux kernel user’s and administrator’s guide/Device Mapper

 类似资料: