runsisi's

technical notes

设置 docker 容器根卷大小

2019-10-26 runsisi#docker

docker 创建的容器根卷大小默认是 10G,显然这太小了,修改这一大小有些小麻烦,记录如下(开发环境)。

增加配置文件:

$ sudo vi /etc/docker/daemon.json
{
  "storage-driver": "devicemapper",
  "storage-opts": [
    "dm.basesize=120G",
    "dm.loopdatasize=200G"
  ]
}
$ sudo systemctl restart docker
$ docker info
Client:
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 1
 Server Version: 19.03.4
 Storage Driver: devicemapper
  Pool Name: docker-253:0-537363272-pool
  Pool Blocksize: 65.54kB
  Base Device Size: 128.8GB
  Backing Filesystem: xfs
  Udev Sync Supported: true
  Data file: /dev/loop3
  Metadata file: /dev/loop4
  Data loop file: /var/lib/docker/devicemapper/devicemapper/data
  Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
  Data Space Used: 269.5MB
  Data Space Total: 214.7GB
  Data Space Available: 163.1GB
  Metadata Space Used: 17.9MB
  Metadata Space Total: 2.147GB
  Metadata Space Available: 2.13GB
  Thin Pool Minimum Free Space: 21.47GB
  ...

镜像需要删掉并重新 pull(不是简单的 untag):

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
runsisi             centos7.6           a175329eed30        3 hours ago         490MB
centos              7.6.1810            f1cb7c7d58b7        7 months ago        202MB
$ docker rmi f1cb7c7d58b7
Error response from daemon: conflict: unable to delete f1cb7c7d58b7 (cannot be forced) - image has dependent child images
$ docker rmi a175329eed30 f1cb7c7d58b7
Untagged: runsisi:centos7.6
Deleted: sha256:a175329eed3000ff2f6fb824226ae81625e5bbced4b2efe7cedd20c15a9e409f
Deleted: sha256:40c2d448a8fc80b4290aa5dc67ee160b8d947bd238e702b87bb634d8795e6569
Untagged: centos:7.6.1810
Untagged: centos@sha256:62d9e1c2daa91166139b51577fe4f4f6b4cc41a3a2c7fc36bd895e2a17a3e4e6
Deleted: sha256:f1cb7c7d58b73eac859c395882eec49d50651244e342cd6c68a5c7809785f427
Deleted: sha256:89169d87dbe2b72ba42bfbb3579c957322baca28e03a1e558076542a1c1b2b4a
$ docker pull centos:7.6.1810
$ docker run -it --rm centos:7.6.1810
[root@39a0725d9f3c /]# df -h
Filesystem                                                                                           Size  Used Avail Use% Mounted on
/dev/mapper/docker-253:0-537363272-018adb8e4ad8299abd96ca3ba0a0cbdf0bd4b6b09b7b50a415ffbd66ea26c7cc  100G  254M  100G   1% /
tmpfs                                                                                                 64M     0   64M   0% /dev
tmpfs                                                                                                 95G     0   95G   0% /sys/fs/cgroup
shm                                                                                                   64M     0   64M   0% /dev/shm
/dev/mapper/hust-root                                                                                214G   62G  152G  29% /etc/hosts
tmpfs                                                                                                 95G     0   95G   0% /proc/acpi
tmpfs                                                                                                 95G     0   95G   0% /proc/scsi
tmpfs                                                                                                 95G     0   95G   0% /sys/firmware

参考资料

Deep dive into Docker storage drivers

http://jpetazzo.github.io/assets/2015-03-03-not-so-deep-dive-into-docker-storage-drivers.html

Increasing the Base Device Size on Docker Daemon Restart

https://www.projectatomic.io/blog/2016/03/daemon_option_basedevicesize/

devicemapper - a storage backend based on Device Mapper

https://github.com/moby/moby/tree/master/daemon/graphdriver/devmapper

dockerd - Daemon storage-driver

https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-storage-driver