Search code examples
windowsdockerdocker-desktop

How to set the maximum storage space allowed in a Docker container's writable layer?


I want to use Docker's storage_opt CLI flag to create containers that have a maximum storage allowance. I'm using Windows, and all the guides and examples from Docker to third-party advice all centres around Linux. How do I apply this storage want to WSL Windows Docker?

How do I emulate the following command on Windows:

Command:

docker run ubuntu:latest --mem_limit 100m --name xyz --storage_opt size=100m

Error:

("--storage-opt is supported only for overlay over xfs with 'pquota' mount option")

List of things I've read/tried:

I understand I have to somehow change Docker's filesystem to overlay with xfs with some storage flag or environmental variable, but I don't understand where in the stack that is (on my system, or in the image) or if I'm thinking about it completely wrong.

All I'm after is a way to set a ceiling on the amount of storage (say 100MB) on a Docker container I build, and presumably be able to edit it. I believe this is best done through Docker, but I could be wrong - thanks for any help.


Solution

  • According to the documentation:

    For the devicemapper, btrfs, windowsfilter and zfs graph drivers, user cannot pass a size less than the Default BaseFS Size. For the overlay2 storage driver, the size option is only available if the backing fs is xfs and mounted with the pquota mount option. Under these conditions, user can pass any size less than the backing fs size.

    Meaning that you can't use the --storage-opt size=100m flag to specify an storage limit in a container basis, since Windows backing fs is NTFS and not XFS.

    This being said, you can try to limit Docker's sandbox size configuring the Docker daemon with the following:

    net stop docker
    dockerd --unregister-service
    dockerd --register-service --storage-opt size=10G
    net start docker
    

    Where size is the maximum you want Docker to use for the whole sandbox.