Docker Limit Quota Folder

In this article, we will discuss how to create and mount a limited quota folder using Docker. This can be useful when you want to restrict the amount of disk space a specific folder can use within a Docker container.

Prerequisites

Before we begin, make sure you have Docker installed on your system. You can download and install Docker from the official Docker website (https://www.docker.com/).

Creating a Limited Quota Folder

To create a limited quota folder, follow these steps:

  1. Create a file with the desired size:

    1
    2
    
    $ touch 2gbarea
    $ truncate -s 2G 2gbarea
  2. Format the file as an ext4 filesystem:

    1
    
    $ mke2fs -t ext4 -F 2gbarea

    This command will create an ext4 filesystem within the 2gbarea file.

  3. Mount the filesystem:

    1
    
    $ sudo mount 2gbarea up

    This will mount the 2gbarea filesystem on the up directory.

  4. Verify the mount:

    1
    
    $ df -h up

    This command will display the size, usage, and available space of the up directory.

Automating the Mount Process

To automate the mount process and ensure it persists across system reboots, you can modify the /etc/fstab file. Here’s how:

  1. Open the /etc/fstab file in a text editor with root privileges:

    1
    
    $ sudo vim /etc/fstab
  2. Add an entry for the mounted filesystem at the end of the file:

    2gbarea up    auto nosuid,nodev,nofail,x-gvfs-show 0 0

    Alternatively, you can use the UUID (Universal Unique Identifier) of the filesystem:

    UUID=bf1b2ee8-a7df-4a57-9d05-a8b60323e2bf /up    auto nosuid,nodev,nofail,x-gvfs-show 0 0

    Replace bf1b2ee8-a7df-4a57-9d05-a8b60323e2bf with the actual UUID obtained from the sudo blkid command.

  3. Save and close the file.

Now, whenever the system boots, the 2gbarea filesystem will be automatically mounted on the up directory with the specified options.

Conclusion

In this article, we have learned how to create and mount a limited quota folder using Docker. By following these steps, you can effectively restrict the disk space usage of a specific folder within a Docker container.

0%