How is the rootfs size of a docker container decided?

佐手、 提交于 2020-03-19 06:46:22

问题


On one system, the disk size of the Docker container is like this:

root@b65c6518f583:/# df -h
Filesystem                                                                                           Size  Used Avail Use% Mounted on
/dev/mapper/docker-253:0-202764498-b65c6518f5837667e7021971a97aebd382dddca6b3ecf4167472ebe17f16aace   99G  268M   94G   1% /
tmpfs                                                                                                5.8G     0  5.8G   0% /dev
shm                                                                                                   64M     0   64M   0% /dev/shm
tmpfs                                                                                                5.8G     0  5.8G   0% /sys/fs/cgroup
tmpfs                                                                                                5.8G   96K  5.8G   1% /run/secrets
/dev/mapper/rhel-root                                                                                 50G   20G   31G  40% /etc/hosts

We can see the rootfs size is 99G. While in another system, the disk size of the Docker container is like this:

53ac740bd09b:/ # df -h
Filesystem                                                                                       Size  Used Avail Use% Mounted on
/dev/mapper/docker-8:8-4202821-2a6f330df1b7b37d55a96b098863f81e4a7f1c39fcca3f5fa03b57998cb33427  9.8G  4.4G  4.9G  48% /
tmpfs                                                                                            126G     0  126G   0% /dev
tmpfs                                                                                            126G     0  126G   0% /sys/fs/cgroup
/dev/sda8                                                                                         97G   11G   82G  12% /data
shm                                                                                               64M     0   64M   0% /dev/shm

The rootfs size is only 9.8G.

How is the rootfs size of a docker container decided? How can I modify the value of rootfs size?


回答1:


The default size for a container is 10 GB, and you can change it.

Here is an excerpt from:
https://docs.docker.com/engine/reference/commandline/daemon/

dm.basesize

Specifies the size to use when creating the base device, which limits the size of images and containers. The default value is 10G. Note, thin devices are inherently “sparse”, so a 10G device which is mostly empty doesn’t use 10 GB of space on the pool. However, the filesystem will use more space for the empty case the larger the device is.

The base device size can be increased at daemon restart which will allow all future images and containers (based on those new images) to be of the new base device size.

Examples:

$ docker daemon --storage-opt dm.basesize=50G

This will increase the base device size to 50G. The Docker daemon will throw an error if existing base device size is larger than 50G. A user can use this option to expand the base device size however shrinking is not permitted.

This value affects the system-wide “base” empty filesystem that may already be initialized and inherited by pulled images. Typically, a change to this value requires additional steps to take effect:

$ sudo service docker stop

$ sudo rm -rf /var/lib/docker

$ sudo service docker start

Example use:

$ docker daemon --storage-opt dm.basesize=20G



回答2:


If you would like the docker container to be more than the default size, this tutorial accomplished the task. I know it will work for CentOs 7. With CentOs 6 you only need to change the xfs_growfs to resize2fs.

I was using docker 1.7



来源:https://stackoverflow.com/questions/36274815/how-is-the-rootfs-size-of-a-docker-container-decided

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!