如何确定Docker容器的rootfs大小? [英] How is the rootfs size of a docker container decided?
问题描述
在一个系统上,Docker容器的磁盘大小如下:
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
我们可以看到rootfs的大小为99G.在另一个系统中,Docker容器的磁盘大小如下:
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
rootfs大小仅为9.8G.
The rootfs size is only 9.8G.
如何确定Docker容器的rootfs大小?如何修改rootfs size的值?
How is the rootfs size of a docker container decided? How can I modify the value of rootfs size?
推荐答案
容器的默认大小为10 GB,您可以更改它.
The default size for a container is 10 GB, and you can change it.
以下摘录自:
https://docs.docker.com/engine/reference/commandline/daemon/
Here is an excerpt from:
https://docs.docker.com/engine/reference/commandline/daemon/
dm.basesize
指定创建基本设备时要使用的大小,这会限制 图片和容器的大小.默认值为10G.笔记, 精简设备本来就是稀疏"的,所以10G设备主要是 空不占用池上的10 GB空间.但是,文件系统 设备越大,空盒将占用更多空间.
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.
示例:
$ docker daemon --storage-opt dm.basesize=50G
这会将基本设备的大小增加到50G. Docker守护程序将 如果现有基本设备的大小大于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容器的rootfs大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!