Why is Docker using 95% of my VM’s disk when the VM has 150 GB?

0
6
Asked By MellowQuasar47 On

I set up an Ubuntu Server VM with Docker managed through Portainer. The virtual disk is about 150 GB, but the root filesystem containing /var/lib/docker is only 15 GB and is already 95% full. Docker reports about 8.6 GB of images, 2.7 MB of containers, and 824 MB of volumes, with no meaningful reclaimable space. The container JSON logs are also relatively small.

I'm trying to determine what is consuming the remaining space under /var/lib/docker. Is roughly 14 GB unreasonable for these containers, and what commands should I use to inspect it? If the Docker data is within the normal range, how can I allocate the unused space on the VM's disk to the root filesystem?

The disk layout appears to be a 152 GB disk with a 2 GB boot partition, a 30 GB LVM partition, and a 15 GB logical volume mounted at /.

3 Answers

Answered By QuietMaple31 On

You could move Docker’s data root to a separate, larger filesystem instead of expanding `/`. Stop Docker first, copy the existing directory while preserving ownership and permissions, then set the new location in `/etc/docker/daemon.json`:

`{"data-root":"/data/docker"}`

A typical migration is to stop both Docker and its socket, use `rsync -aHAX` to copy `/var/lib/docker/` to the new location, configure `data-root`, and start Docker again. Make sure the new filesystem is mounted before Docker starts. Log rotation is also worth configuring so container JSON logs cannot grow without limit.

Answered By BluePineapple6 On

You can first locate the usage with something like `sudo ncdu -x /var/lib/docker` or with `sudo du -xhd1 /var/lib/docker | sort -h`. Check directories such as `overlay2`, `volumes`, `image`, and `containers`. Also inspect the whole root filesystem, since the space may not actually belong to Docker.

If `du` does not account for the space reported by `df`, look for deleted files still held open by a process with `sudo lsof +L1`. Docker’s storage layer can also contain data written inside containers rather than in declared volumes, so `overlay2` may be larger than the image totals suggest.

Answered By CedarFox_82 On

The important detail is that the VM’s virtual disk is 152 GB, but the partition and logical volume are much smaller. Your root filesystem is only 15 GB, so Docker is filling that filesystem; the rest of the virtual disk has not been assigned to it yet.

Before changing anything, make a backup or snapshot and verify the layout with `lsblk`, `pvs`, `vgs`, and `df -Th`. If the filesystem is ext4, the usual expansion sequence is:

`sudo growpart /dev/sda 3`
`sudo pvresize /dev/sda3`
`sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv`
`sudo resize2fs /dev/ubuntu-vg/ubuntu-lv`

Use the actual device and volume-group names shown by your system. For XFS, use `xfs_growfs /` instead of `resize2fs`. Then confirm the result with `df -h /`.

MellowQuasar47 -

That explains it. My disk listing shows `/dev/sda` at 152 GB, `/dev/sda3` at 30 GB, and the root logical volume at only 15 GB. I’ll verify the filesystem type and expand the partition, physical volume, logical volume, and filesystem in that order, after taking a snapshot.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.