gpt4 book ai didi

docker - docker容器的rootfs大小是如何决定的?

转载 作者:行者123 更新时间:2023-12-02 06:17:54 25 4
gpt4 key购买 nike

在一个系统上,Docker容器的磁盘大小是这样的:

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

我们可以看到rootfs大小为99G。而在另一个系统中,Docker容器的磁盘大小是这样的:

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

rootfs大小只有9.8G。

docker容器的rootfs大小是如何决定的?如何修改rootfs大小的值?

最佳答案

容器的默认大小为 10 GB,您可以更改它。

以下摘录自: 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

使用示例:

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

关于docker - docker容器的rootfs大小是如何决定的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36274815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com