Skip to documentation

No Space Left on /var/lib/docker

Moving existing Docker data to a dedicated LVM logical volume using the copy-before-mount method.

Stop Docker Service

You must stop Docker service first or files will change during copy.

systemctl stop docker

Confirm it’s stopped:

systemctl status docker

Create The Physical Volume

A physical volume makes a disk available for LVM to use.

Replace /dev/sdb with your actual unused disk. pvcreate writes LVM metadata to the device. Do not use your OS disk, a mounted device, or a disk containing data you need to keep. If the disk already appears in pvs, do not initialize it again.

Initialize the new disk as an LVM physical volume:

pvcreate /dev/sdb

Verify that it appears in the physical volume list:

pvs

Create The Volume Group

A volume group pools physical volume storage so you can allocate logical volumes from it.

vgcreate rocky8 /dev/sdb

Check the available space:

vgs rocky8

The VFree column must have enough space for the 20G logical volume created below. Choose a larger logical volume size if your existing Docker data needs more room, and make sure the volume group has enough free space for that size.


Create the new Logical Volume and filesystem

Example: add 20GB

lvcreate -n docker -L 20G rocky8
mkfs.xfs /dev/mapper/rocky8-docker

Create mount point:

mkdir -p /mnt/newdocker

Mount it temporarily:

mount /dev/mapper/rocky8-docker /mnt/newdocker

Copy existing Docker data with permissions preserved

rsync -aHAXv /var/lib/docker/ /mnt/newdocker/

Rename the old directory (just in case)

mv /var/lib/docker /var/lib/docker.bak
mkdir /var/lib/docker

Update /etc/fstab so it persists after reboot

Edit:

vi /etc/fstab

Add this line:

/dev/mapper/rocky8-docker  /var/lib/docker  xfs  defaults  0  0

Mount it:

mount -a

Verify:

df -h | grep docker

Restart Docker

systemctl start docker

Verify containers/images still exist:

docker ps -a
docker images

Once confirmed β€” cleanup old data

rm -rf /var/lib/docker.bak

Safety Check (optional)

Take a quick checksum diff before deleting:

diff -r /var/lib/docker.bak /var/lib/docker