Docker - 限制磁盘

2021-11-24

限制挂载目录磁盘

# 安装
dd if=/dev/zero of=/data-hdd/img/xxx.img bs=10M count=10240
losetup /dev/loop0 /data-hdd/img/xxx.img
mkfs.xfs /dev/loop0
mount -t xfs /dev/loop0 /data-hdd/vscode/xxx

#卸载
umount /data-hdd/vscode/xxx
losetup -d /dev/loop0
rm /data-hdd/img/xxx.img
#!/bin/bash
# 限制挂载目录磁盘
# 服务器重启后会消息,需实现开机自启,因此不能在/etc/fstab下编写挂载
#!/bin/bash
basepath=$(cd `dirname $0`; pwd)
list_file=${basepath}/"dev_manager.txt"
data_path="/data-hdd/vscode"
img_path="/data-hdd/img"
mkdir -p ${data_path} ${img_path}

cat -n ${list_file} | grep -v '#' | while read line
do
    line=($line)
    num=${line[0]}
    name=${line[1]}
#    dd if=/dev/zero of=${img_path}/${name}.img bs=10M count=10240
    losetup /dev/loop${num} ${img_path}/${name}.img
#    mkfs.xfs /dev/loop${num}
    mount -t xfs /dev/loop${num} ${data_path}/${name}
done

限制overlay磁盘

docker run --storage-opt dm.basesize=40G