Search code examples
dockerubuntu-18.04docker-volume

Disk space issue in Docker for Windows


I have a Ubuntu container that has a volume where my postgresql database is stored. My database has run out of space as it has failed over, and I can see disk usage is at 100% when I query disk stats on the Ubuntu container:

root@b2b1bc6c247c:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay          59G   58G     0 100% /
tmpfs            64M     0   64M   0% /dev
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
shm              64M     0   64M   0% /dev/shm
/dev/sda1        59G   58G     0 100% /etc/hosts
tmpfs           3.9G     0  3.9G   0% /proc/acpi
tmpfs           3.9G     0  3.9G   0% /sys/firmware

I have increased the Disk image size to 160GB in the Docker for Windows settings and applied the changes, however when I restart the container the new disk space has not been allocated.

I'm quite confused as to whether this is an issue with the container that is reporting 100% usage or the volume where the data is actually being stored.


Solution

  • I ran into this problem a while back as well. I'm not sure if the Stable version has the fix added yet, but I believe they fixed it in the Edge version.

    Either way, you can do it through the Hyper-V Manager. You click the Edit Disk item and you can then expand the disk size there. Make sure you completely shutdown and exit Docker first.

    enter image description here

    Also, after I did mine I optimized it, like this:

    To Optimize/Shrink the VM (in Powershell):

    1. Mount-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\DockerDesktop.vhdx" -ReadOnly
    2. Optimize-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\DockerDesktop.vhdx" -Mode Full
    3. Dismount-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\DockerDesktop.vhdx