Skip to content

Instantly share code, notes, and snippets.

@kzzzr
Last active June 4, 2024 10:01
Show Gist options
  • Save kzzzr/fef4c9c88f301c282275e6d451e080f5 to your computer and use it in GitHub Desktop.
Save kzzzr/fef4c9c88f301c282275e6d451e080f5 to your computer and use it in GitHub Desktop.
Docker: move persistent volumes (mounts) into another filesysytem WITHOUT data losses

The problem you face

You have created a VM, deployed your services in Docker on it, services (for example, Kafka + Kafka Connect) started writing data.

Suddenly you find that the disk volume is running out.

df -h

What to do? How to migrate Docker Volumes and avoid the Disk full error?

Solution steps

  • Add a new Filesystem with enough space
  • Stop containers
  • Disable Docker services
  • Unmount docker overlay filesystems
  • Move data to the new partition
  • Make changes to the Docker daemon.json configuration file
  • Enable Docker services
  • Start containers
# Stop Docker containers
docker compose stop
# Stop Docker services
systemctl stop docker
systemctl stop docker.socket
# Unmount docker filesystems
umount /var/lib/docker/overlay2/*/*
# Move data
mv /var/lib/docker/ /mnt/${DESTINATION}/
# Edit Docker service configuration file:
nano /etc/docker/daemon.json
# Add or modify the data-root configuration option to point to the new directory:
{
"data-root": "/mnt/path/docker"
}
# Save and close the file.
# Start the Docker service:
systemctl start docker
systemctl start docker.socket
# Start Docker containers
docker compose start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment