Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the rootfs size of a docker container decided?

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?

like image 279
Nan Xiao Avatar asked Oct 20 '25 08:10

Nan Xiao


1 Answers

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
like image 78
user2915097 Avatar answered Oct 21 '25 21:10

user2915097



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!