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:

volumes:
 SOMENAME: {}
 tmpfs:
  driver: local
  driver_opts:
   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