Sometimes while running a command inside of a docker container, the container itself will run out of disk space and things can fail (sometimes in strange ways). This is not a guide on how to allocate resources, but a quick cookbook on how to free up disk space inside a container. See below for links to more resources and reading.
See Limit disk size and bandwidth of a Docker container.
If the storage driver is aufs
(the default storage driver, except for on RedHat) you can resize the VM disk image used
for containers. On Docker for Mac this is located at ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2
. Learn how to increase the size of a qcow2 volume.
You can validate your storage container method by running docker info
.
Make sure you have qemu-img
installed (brew install qemu
). Then resize the volume:
qemu-img resize ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2 +1GB
Note that sometimes this forces me into a loop of having to restart Docker, and sometimes reset settings to default; rinse and repeat. It's not ideal and can cause the size of the Docker.qcow2
image to balloon to unfortunate sizes, but the alternative for me was that I couldn't use docker containers at all. ¯_(ツ)_/¯
$ docker run --rm --privileged debian:jessie df -h
Filesystem Size Used Avail Use% Mounted on
none 19G 18G 0 100% /
tmpfs 999M 0 999M 0% /dev
tmpfs 999M 0 999M 0% /sys/fs/cgroup
/dev/vda1 19G 18G 0 100% /etc/hosts
shm 64M 0 64M 0% /dev/shm
It's the first filesystem listed that you want to optimize, sometimes called none
, sometimes overlay
.
You can alias this command for ease of use:
alias docker_free_space="docker run --rm --privileged debian:jessie df -h"
$ docker ps -q -a -f status=exited | xargs -n 100 docker rm -v
Warning: this can remove cached images that may take a long time to rebuild or download.
$ docker images -q --filter "dangling=true" | xargs -n 100 docker rmi
$ docker run --rm --privileged debian:jessie df -h
Filesystem Size Used Avail Use% Mounted on
none 19G 5.2G 13G 31% /
tmpfs 999M 0 999M 0% /dev
tmpfs 999M 0 999M 0% /sys/fs/cgroup
/dev/vda1 19G 5.2G 13G 31% /etc/hosts
shm 64M 0 64M 0% /dev/shm
This usually frees up more than enough space for me.