Table of Contents
Managing Docker storage efficiently is becoming more important as cloud-native workloads scale and disk usage grows rapidly. Teams running Docker on cloud VMs often hit a common bottleneck: the root disk fills up quickly with images, containers, logs, and volumes.
While Docker defaults to storing everything under /var/lib/docker, this can cause multiple issues:
- The OS disk becomes unusable
- Containers fail during builds
- Disk I/O slows down the entire VM
- Upgrades and backups become risky
But here's the good news: Docker doesn’t need to store data in /var/lib/docker.
You can easily migrate everything to an external attached disk, mounted anywhere, and configure Docker to use that new storage path.
This guide walks through the complete process of mounting an external disk at a custom path and migrating the Docker data-root, without overwriting the system directory.
This is the cleanest, safest way to expand Docker storage, used in production by DevOps teams across clouds.
Let’s begin.
Step-by-Step Guide
Step 1 — Identify the external disk
lsblkFind the unmounted disk (e.g., /dev/sda).
Step 2 — Format the disk
sudo mkfs.ext4 /dev/sdaStep 3 — Create mount point
sudo mkdir -p /mnt/docker-storageStep 4 — Mount the disk
sudo mount /dev/sda /mnt/docker-storageVerify:
df -h | grep docker-storageStep 5 — Persist the mount
echo '/dev/sda /mnt/docker-storage ext4 defaults 0 0' | sudo tee -a /etc/fstabStep 6 — Stop Docker
sudo systemctl stop dockerStep 7 — Copy existing Docker data (if any)
sudo cp -a /var/lib/docker/* /mnt/docker-storage/If empty, skip—safe.
Step 8 — Point Docker to the new data-root
sudo mkdir -p /etc/docker
echo '{"data-root": "/mnt/docker-storage"}' | sudo tee /etc/docker/daemon.jsonStep 9 — Start and verify
sudo systemctl start docker
docker info | grep "Docker Root Dir"Expected:
Docker Root Dir: /mnt/docker-storageTest with:
docker pull nginx
Check size:
sudo du -sh /mnt/docker-storage4. Why This Option Is Better Than Mounting Over /var/lib/docker
Feature | Default Approach (overwrite /var/lib/docker) | Custom Mount Path |
|---|---|---|
Flexibility | ❌ Low | ✔ High |
Can store other files | ❌ No | ✔ Yes |
Cleaner migration | ❌ No | ✔ Yes |
Safer for production | ⚠️ Medium | ✔ High |
Custom mount paths | ❌ No | ✔ Yes |
Using a dedicated mount path provides better control, avoids conflicts with system directories, and offers a clean separation between OS-level storage and Docker data.
Conclusion
Moving Docker storage to an external disk is one of the simplest ways to improve performance, reliability, and scalability on any cloud VM or bare-metal server.
By attaching a new disk, mounting it at a dedicated path, and updating Docker’s data-root configuration, you gain:
- A clean separation between OS and Docker
- Zero-downtime migration
- Flexible storage layout
- Better disk performance
- Safer long-term maintenance
Whether you're optimizing a development server or preparing a production deployment, this method gives Docker the storage space it needs—without touching critical system directories..