启动一个容器
docker run -it ubuntu:ssh /bin/bash
➜ ubuntu64 docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9fb1a5e9da0b ubuntu:ssh "/bin/bash" 13 seconds ago Up 12 seconds distracted_banach
停止容器
docker stop 9fb1a5e9da0b
例如分配一个1T的磁盘给9fb1a5e9da0b
- 创建一个1T的空文件
dd of=data1 seek=1048576 bs=1M count=0
实际没占用真实硬盘空间 - 转成块设备,格式化成ext4
mkfs.ext4 -F data1
- 创建临时挂载目录用作同步9fb1a5e9da0b容器的内容
mkdir tmp_mount
mount data1 tmp_mount
rsync -rtv /var/lib/docker/aufs/diff/9fb1a5e9da0b79938073f10ababa1cd59f74d969f0f51819e5bc82b2652bd6df/ tmp_mount
9fb1a5e9da0b…..是容器的IDumount tmp_mount
rm -fr tmp_mount
rm -fr /var/lib/docker/aufs/diff/9fb1a5e9da0b79938073f10ababa1cd59f74d969f0f51819e5bc82b2652bd6df/
mkdir /var/lib/docker/aufs/diff/9fb1a5e9da0b79938073f10ababa1cd59f74d969f0f51819e5bc82b2652bd6df/
mount data1 /var/lib/docker/aufs/diff/9fb1a5e9da0b79938073f10ababa1cd59f74d969f0f51819e5bc82b2652bd6df/
- 重新启动
docker start 9fb1a5e9da0b
docker attach 9fb1a5e9da0b
df -h
Filesystem Size Used Avail Use% Mounted on
none 1008G 88M 957G 1% /
tmpfs 997M 0 997M 0% /dev
shm 64M 0 64M 0% /dev/shm
/dev/disk/by-uuid/27a1bcc3-27e8-41f8-bd33-c47cf403544c 16G 6.3G 8.7G 42% /etc/hosts