添加docker启动参数修改存储大小
添加--storage-opt 参数设置thin-pool和元数据大小
--storage-opt dm.loopmetadatasize=10G --storage-opt dm.loopdatasize=400G 修改thin-pool池大小为400g,元数据大小为10g[root@docker opt]# cat /etc/sysconfig/docker|grep -v "^#"OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --graph=/opt/docker --storage-opt dm.loopmetadatasize=10G --storage-opt dm.loopdatasize=400G'if [ -z "${DOCKER_CERT_PATH}" ]; then DOCKER_CERT_PATH=/etc/dockerfi--storage-opt dm.loopmetadatasize=10G --storage-opt dm.loopdatasize=400G
也可以修改/usr/lib/systemd/system/docker.service 文件,但是要使用systemctl daemon-reload重载配置文件
重启docker,不建议使用systemctl restart docker 命令,存在不会卸载环回设备直接启动docker,导致存储大小无法修改
[root@docker opt]# systemctl stop docker[root@docker opt]# systemctl start docker
查看修改后的存储容量
[root@docker opt]# docker info|grep -i data WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device. Data file: /dev/loop0 Metadata file: /dev/loop1 Data Space Used: 907.9 MB Data Space Total: 429.5 GB Data Space Available: 14.89 GB Metadata Space Used: 3.92 MB Metadata Space Total: 10.74 GB Metadata Space Available: 10.73 GB Data loop file: /opt/docker/devicemapper/devicemapper/data Metadata loop file: /opt/docker/devicemapper/devicemapper/metadata
使用truncat 命令扩大环回设备文件大小
先找到存储的环回设备文件路径
[root@docker opt]# docker info|grep "loop file" Data loop file: /opt/docker/devicemapper/devicemapper/data Metadata loop file: /opt/docker/devicemapper/devicemapper/metadata
使用truncate 命令扩大空间
[root@docker opt]# truncate -s 800g /opt/docker/devicemapper/devicemapper/data #扩大thin-pool到800g[root@docker opt]# truncate -s 20g /opt/docker/devicemapper/devicemapper/metadata #扩大元数据到20g
重启docker,不建议使用systemctl restart docker 命令,存在不会卸载环回设备直接启动docker,导致存储大小无法修改
[root@docker opt]# systemctl stop docker[root@docker opt]# systemctl start docker
在重新挂载环回设备后,环回设备容量变化后docker 会自动更新devicemap的映射表,也可以在重启前手动完成更新操作,如下:
此方法无法修改metadata space的大小
查看环回设备在内存中的大小信息为1000g
[root@docker devicemapper]# echo $[ $(sudo blockdev --getsize64 /dev/loop0) / 1024 / 1024 / 1024 ]1000
使用使用truncate 命令扩大空间
[root@docker devicemapper]# truncate -s 2000g data [root@docker devicemapper]# ll -htotal 175M-rw------- 1 root root 2.0T Oct 10 01:13 data-rw------- 1 root root 100G Oct 10 00:52 metadata
查看在内存中的信息仍然为1000g
[root@docker devicemapper]# echo $[ $(sudo blockdev --getsize64 /dev/loop0) / 1024 / 1024 / 1024 ]1000
重新加载环回设备在内存中的信息
[root@docker devicemapper]# losetup -c /dev/loop0[root@docker devicemapper]# echo $[ $(sudo blockdev --getsize64 /dev/loop0) / 1024 / 1024 / 1024 ]2000
查看docker的存储thin-pool池的名称
[root@docker devicemapper]# dmsetup status | grep ' thin-pool ' | awk -F ': ' {'print $1'}docker-253:0-34124585-pool
查看devicemap的映射表中docker存储thin-pool池信息
[root@docker devicemapper]# dmsetup table docker-253:0-34124585-pool0 2097152000 thin-pool 7:1 7:0 128 32768 1 skip_block_zeroing
更新映射表中的信息,先挂起thin-pool池,在修改表中信息,在退出挂起状态
[root@docker devicemapper]# dmsetup suspend docker-253:0-34124585-pool[root@docker devicemapper]# dmsetup reload docker-253:0-34124585-pool --table '0 4194304000 thin-pool 7:1 7:0 128 32768 1 skip_block_zeroing' #4194304000 是扇区大小值,对应为2T,这儿只修改了逻辑卷组对应到物理磁盘的扇区大小[root@docker devicemapper]# dmsetup resume docker-253:0-34124585-pool
参考资料
http://www.cnblogs.com/hustcat/p/3908985.html
https://www.ibm.com/developerworks/cn/linux/l-devmapper/index.html#resources https://docs.docker.com/engine/userguide/storagedriver/device-mapper-driver/#increase-capacity-on-a-running-device