Docker Community Forums

Share and learn in the Docker community.

How to limit size of docker containers after created to manage server disk

Four containers are running for two customers in the same node/server (each of them have two containers). Now they can consume the whole disk space of the server, but I want to limit their usage. For example, containers A and B can only use 10GB, and C and D can only use 5GB.

In order to reach this, I ran a VM in Oracle VirtualBox with XFS format, did edit /etc/default/grub to GRUB_CMDLINE_LINUX_DEFAULT="rootflags=uquota,pquota" and reboot the VM as mentioned here and here, and also have done what’s said in here.

Then after having rebooted the VM, I did docker exec -it NAME bash and then dd if=/dev/zero of=somefile bs=1G count=200", and I saw a 200GB file is created with no issue.

I run container with docker run -d --storage-opt --size=10G IMAGE and tested dd and it was created.

I also tried with docker-compose to have multiple containers in one group, like this:

  driver: local
   o: "size:10G"
   device: tmpfs
   type: tmpfs

Are there ways to manage hard disk so that containers would not consume more than some defined sizes?

tmpfs is ramdisk storage. To limit disk volumes you’ll need to use a storage driver plugin. See Use Docker Engine plugins | Docker Documentation

I know flocker and convoy provide quota options.

1 Like

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 been merged since then. 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

Documentation: docker run/#Set storage driver options per container.