1

I would need a way to limit a container's disk size, mainly to test how the app behaves when there is not enough space on disk. The Docker container I'm trying to run uses a Linux image. The tricky bit is that I need to do it on Windows. I know about using tmpfs and some other tricks to do this, but none of them works on Windows. I imagine I could partition my actual disk and share that one to the container, but I'd like to avoid that for easier re-using (like for other people).

I don't really care how the solution would work, of course, I would prefer this to be done with a mount inside the docker container so that I can limit only the data folder, not the whole container and also preferably to work with docker-compose as well, but I guess this is pretty tricky anyway so even without this it would be helpful!

  • On Windows, with a Docker Windows image, using Windows host kernel? Or on Windows, using a Linux VM kernel through HyperV, with a Docker Linux image, mounting Linux volumes? (using xfs quota: https://stackoverflow.com/a/59423525/6309) – VonC Sep 13 '20 at 20:21
  • @VonC On Windows, using a Linux image. So, being Windows the filesystem is NTFS. – Bogdan Condurache Sep 13 '20 at 23:57
  • ```docker run -ti --storage-opt size=20g centos bash``` or limit the size of the Docker mount folder through Windows. – Johnny Sep 14 '20 at 03:43
  • @BogdanCondurache So you would be using a Linux VM in order to have access to a Linux kernel to run your Linux Docker image. As a result, your mounted volume would be a Linux-based filesystem, *not* NTFS. – VonC Sep 14 '20 at 05:51
  • @VonC Yes, but I can't run commands against the virtualized Linux. – Bogdan Condurache Sep 14 '20 at 07:48

1 Answers1

0

You should be able to crate a volume (for your Linux image) with size restriction.
From docker volume create:

The built-in local driver on Linux accepts options similar to the linux mount command. You can provide multiple options by passing the --opt flag multiple times. Some mount options (such as the o option) can take a comma-separated list of options. Complete list of available mount options can be found here.

For example, the following creates a tmpfs volume called foo with a size of 100 megabyte and uid of 1000.

$ docker volume create --driver local \
   --opt type=tmpfs \
   --opt device=tmpfs \
   --opt o=size=100m,uid=1000 \
   foo

You can then declare that volume to be mounted, in your docker-compose.yml.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Using tmpfs does not work on a Windows or Mac machine, it's Linux only, as described in their documentation. – Bogdan Condurache Sep 14 '20 at 07:47
  • @BogdanCondurache So you would need to use Linux VM, since they are available on Windows 10 (assuming you are using a recent Windows 10) – VonC Sep 14 '20 at 08:08