如何限制Docker可用于容器的文件系统空间 [英] How to limit Docker filesystem space available to container(s)

查看:689
本文介绍了如何限制Docker可用于容器的文件系统空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一般情况是我们有一个服务器集群,我们要使用Docker设置虚拟集群。



为此,我们创建了Dockerfiles对于不同的服务(Hadoop,Spark等)。



关于Hadoop HDFS服务,我们有这样的情况:docker容器可用的磁盘空间等于磁盘服务器可用的空间。我们希望在每个容器的基础上限制可用的磁盘空间,以便我们可以动态地生成一些额外的数据库,其中存储大小有助于HDFS文件系统。



有想法使用ext4格式化的环回文件,并将它们安装在我们用作docker容器中的卷的目录上。但是,这意味着很大的性能损失。



我发现了另一个问题(限制Docker容器的磁盘大小和带宽),但答案差不多1 5年了 - 关于docker开发的速度 - 是古老的。



哪种方式或存储后端将允许我们




  • 限制每个容器的存储空间

  • 具有近乎裸机的性能

  • 不需要重新分区服务器驱动器


解决方案

您可以指定运行时约束,而不是磁盘空间。



已经请求对磁盘空间的限制( issue 12462 issue 3804 ),但isn没有实现,因为它取决于基础文件系统驱动程序。


此功能将在某些时候添加,但不正确远。现在添加这个功能有点困难,因为大量的代码块从一个地方移动到另一个地方。完成这项工作后,实施此功能应该更容易。



请记住,配额支持不能作为黑客加入到设计版本中必须尽可能多地实施多个存储后端,所以必须以一种方式实现,这样可以轻松地为其他存储后端添加配额支持。







更新2016年8月:如下所示,在 issue 3804 comment PR 24771 PR 24807 已经被合并。 docker run 现在允许为每个容器设置存储驱动程序选项

  $ docker run -it --storage-opt size = 120G fedora / bin / bash 




此(大小)将允许在创建时将容器rootfs大小设置为120G。

此选项仅适用于devicemap,btrfs,overlay2,windowsfilter和zfs图形驱动程序



The general scenario is that we have a cluster of servers and we want to set up virtual clusters on top of that using Docker.

For that we have created Dockerfiles for different services (Hadoop, Spark etc.).

Regarding the Hadoop HDFS service however, we have the situation that the disk space available to the docker containers equals to the disk space available to the server. We want to limit the available disk space on a per-container basis so that we can dynamically spawn an additional datanode with some storage size to contribute to the HDFS filesystem.

We had the idea to use loopback files formatted with ext4 and mount these on directories which we use as volumes in docker containers. However, this implies a large performance loss.

I found another question on SO (Limit disk size and bandwidth of a Docker container) but the answers are almost 1,5 years old which - regarding the speed of development of docker - is ancient.

Which way or storage backend would allow us to

  • Limit storage on a per-container basis
  • Has near bare-metal performance
  • Doesn't require repartitioning of the server drives

解决方案

You can specify runtime constraints on memory and CPU, but not disk space.

The ability to set constraints on disk space has been requested (issue 12462, issue 3804), but isn't yet implemented, as it depends on the underlying filesystem driver.

This feature is going to be added at some point, but not right away. It's a bit more difficult to add this functionality right now because a lot of chunks of code are moving from one place to another. After this work is done, it should be much easier to implement this functionality.

Please keep in mind that quota support can't be added as a hack to devicemapper, it has to be implemented for as many storage backends as possible, so it has to be implemented in a way which makes it easy to add quota support for other storage backends.


Update August 2016: as shown below, and in issue 3804 comment, PR 24771 and PR 24807 have seen then been merged. docker run now allow to set storage driver options per container

$ docker run -it --storage-opt size=120G fedora /bin/bash

This (size) will allow to set the container rootfs size to 120G at creation time.
This option is only available for the devicemapper, btrfs, overlay2, windowsfilter and zfs graph drivers

这篇关于如何限制Docker可用于容器的文件系统空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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