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!

5
  • 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: stackoverflow.com/a/59423525/6309) Commented Sep 13, 2020 at 20:21
  • @VonC On Windows, using a Linux image. So, being Windows the filesystem is NTFS. Commented Sep 13, 2020 at 23:57
  • docker run -ti --storage-opt size=20g centos bash or limit the size of the Docker mount folder through Windows. Commented Sep 14, 2020 at 3: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. Commented Sep 14, 2020 at 5:51
  • @VonC Yes, but I can't run commands against the virtualized Linux. Commented Sep 14, 2020 at 7:48

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Using tmpfs does not work on a Windows or Mac machine, it's Linux only, as described in their documentation.
@BogdanCondurache So you would need to use Linux VM, since they are available on Windows 10 (assuming you are using a recent Windows 10)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.