Adding a Quota for single Docker containers
Opened this issue · 0 comments
Sengorius commented
Goal is to limit the amount of data that is not in the layers of base image, but in the diff of a Docker container.
A goad attempt can be found here: https://stackoverflow.com/questions/29029326/how-to-define-a-disk-quota-for-docker-containers
This one may fit in the DockerExec
.
do_enable_quota() {
local ID=$1
local QUOTA_MB=$2
local LOOPBACK=/var/lib/docker/aufs/diff/$ID-loopback
local LOOPBACK_MOUNT=/var/lib/docker/aufs/diff/$ID-loopback-mount
local DIFF=/var/lib/docker/aufs/diff/$ID
docker stop -t=0 $ID
sudo dd of=$LOOPBACK bs=1M seek=$QUOTA_MB count=0
sudo mkfs.ext4 -F $LOOPBACK
sudo mkdir -p $LOOPBACK_MOUNT
sudo mount -t ext4 -n -o loop,rw $LOOPBACK $LOOPBACK_MOUNT
sudo rsync -rtv $DIFF/ $LOOPBACK_MOUNT/
sudo rm -rf $DIFF
sudo mkdir -p $DIFF
sudo umount $LOOPBACK_MOUNT
sudo rm -rf $LOOPBACK_MOUNT
sudo mount -t ext4 -n -o loop,rw $LOOPBACK $DIFF
docker start $ID
}