正在运行的 Docker 容器何时会耗尽磁盘空间? [英] When does a running Docker container run out of disk space?

查看:55
本文介绍了正在运行的 Docker 容器何时会耗尽磁盘空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多文档,但我仍然不确定这到底是如何工作的.这是一个 Docker 与 VM 的问题.

I've read through so much documentation, and I'm still not sure how this really works. It's a bit of a Docker vs. VM question.

如果我用 2GB 的硬盘启动一个虚拟机并用文件填充它的磁盘,我知道它会在 2GB 的文件后耗尽.

If I start a VM with a 2GB hard drive and fill its disk with files, I know it runs out after 2GB of files.

Docker 是否也以同样的方式工作?我会这么认为.但从我读到的关于UnionFS"的内容来看,它似乎不会耗尽空间.

Does Docker work the same way? I would assume so. But from what I've read about "UnionFS" it seems like it does not run out of space.

那么为什么 Docker volumes" 存在呢?这是否会以某种方式自动扩展 Docker 磁盘空间瞬态?重新启动后,我保存在 Docker 容器中的文件会消失吗?重启容器后怎么样?

So then why do Docker "volumes" exist? Is that automagically expanding Docker disk space transient in some way? Will the files I've saved inside of my Docker container disappear after a reboot? How about after restarting the container?

推荐答案

Docker 的使用 (1.12+) 取决于 Docker 存储驱动程序,可能还有正在使用的物理文件系统.

Docker's usage (1.12+) depends on the Docker storage driver and possibly the physical file system in use.

TL;DR 存储将在所有容器和本地卷之间共享,除非您使用 devicemapper 存储驱动程序或通过 docker run 设置了限制 --storage-opt size=Xzfsbtrfs 驱动程序上运行时.Docker 1.13+ 还支持在 xfs 支持的文件系统上使用 overlay2 的配额大小.

TL;DR Storage will be shared between all containers and local volumes unless you are using the devicemapper storage driver or have set a limit via docker run --storage-opt size=X when running on the zfs or btrfs drivers. Docker 1.13+ also supports a quota size with overlay2 on an xfs backed file system.

对于除 devicemapper 之外的所有存储驱动程序,容器和本地卷存储都受到托管 /var/lib/docker 及其子目录的底层文件系统的限制.一个容器可以填满共享文件系统,然后其他容器就不能再写了.

For all storage drivers, except devicemapper, the container and local volume storage is limited by the underlying file system hosting /var/lib/docker and it's subdirectories. A container can fill the shared file system and then other containers can't write any more.

当使用 devicemapper 驱动程序时,默认的 100G 卷大小为每个容器精简分配".可以使用守护程序选项覆盖默认大小 --storage-opt dm.basesize 选项 或使用 docker run --storage-opt size=2G 在每个容器的基础上设置.

When using the devicemapper driver, a default volume size of 100G is "thin allocated" for each container. The default size can be overridden with the daemon option --storage-opt dm.basesize option or set on a per container basis with docker run --storage-opt size=2G.

对于 zfsbtrfs 驱动程序,因为这两个文件系统都提供简单的构建支持创建具有大小或配额的卷.

The same per container quota support is available for the zfs and btrfs drivers as both file systems provide simple built in support for creating volumes with a size or quota.

xfs 上的 overlay2 存储驱动程序支持从 Docker 开始的每个容器配额1.13.当新的 4.5+ 内核成为标准/通用并且 ext4 和 xfs 配额共享一个通用 API 时,这可能会扩展到 ext4.

The overlay2 storage driver on xfs supporta per container quotas as of Docker 1.13. This will probably be extended to ext4 when new 4.5+ kernels become standard/common and ext4 and xfs quotas share a common API.

Docker 卷与容器分离,可以被视为临时容器的持久存储区域.

Docker volumes are separate from a container and can be viewed as a persistant storage area for an ephemeral container.

Volumes 与 Docker 存储分开存储,并且有自己的插件用于不同的后端.local 是默认后端,它将数据写入/var/lib/docker/volumes,因此保存在容器存储和可能的配额系统之外.

Volumes are stored separately from Docker storage, and have their own plugins for different backends. local is the default backend, which writes data to /var/lib/docker/volumes so is held outside of the containers storage and possible quota system.

如果您想设置每个音量限制,可以使用其他 音量插件在支持它的本地文件系统上.

Other volume plugins could be used if you wanted to set per volume limits on a local file system that supports it.

容器将在容器重启和重启时保持自己的文件状态,直到您<代码>docker rm 容器.卷中的文件在容器移除后仍然存在,并且可以在创建新容器时挂载.

Containers will keep their own file state over a container restart and reboot, until you docker rm the container. Files in a volume will survive a container removal and can be mounted on creation of the new container.

这篇关于正在运行的 Docker 容器何时会耗尽磁盘空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆