Hetzner Cloud Volume for Docker Volume Storage#

At the time of this writing, Hetzner volumes cost 0,052€ per GB per month.

Here we will show how to move /var/lib/docker from instance storage to a cloud volume.

Checklist#

  1. create volume (this creates a temporary mount)

  2. get disk UUID and update /etc/fstab

  3. stop services

  4. move data

  5. umount temporary volume

  6. mount volume to /var/lib/docker/

  7. verify

  8. start services

Commands#

du -sch /var/lib/docker/
docker ps  # nothing running

df -T
# new disk is /dev/sdb mounted on /mnt/HC_Volume_123456789

dev=/dev/sdb
uuid=$(blkid -s UUID -o value $dev)
cat <<EOF >> /etc/fstab
/dev/disk/by-uuid/$uuid /var/lib/docker ext4 discard,nofail,defaults 0 0
EOF

systemctl stop docker.service

mv /var/lib/docker/* /mnt/HC_Volume_123456789/
ls -la /var/lib/docker  # empty
ls -l /mnt/HC_Volume_123456789/

du -sch /var/lib/docker/
systemctl start docker.service

Resizing a Volume’s Filesystem#

You can resize a volume on the fly, but must increase the filesystem’s size afterwards. For ext4:

resize2fs /dev/sdb