๐ณ Docker Data Directory Migration to /app
This document captures the exact commands used to move Dockerโs data directory from /var/lib/docker to /app/docker, along with concise explanations for each step.
๐ฏ Objective
Move Docker storage to a larger partition:
- From:
/var/lib/docker(limited space) - To:
/app/docker(400GB available)
๐ 1. Verify Docker Status
docker psLists running containers to confirm Docker activity.
systemctl status dockerChecks whether the Docker service is running and healthy.
๐ 2. Verify Current Docker Root Directory (Before Change)
docker info | grep "Docker Root Dir"Checks the current Docker data directory to confirm where Docker is storing data before migration.
โ๏ธ 3. Inspect Existing Configuration
ll /etc/docker/Lists Docker configuration directory.
cat /etc/docker/daemon.jsonDisplays current Docker configuration (if present).
โ 4. Stop Docker Service
sudo systemctl stop dockerStops Docker to safely modify its data directory.
๐ 5. Create New Data Directory
sudo mkdir -p /appCreates the target directory for Docker storage.
sudo chown -R root:root /appEnsures correct ownership and permissions.
๐ 6. Copy Existing Docker Data
sudo cp -rf /var/lib/docker /app/Copies all existing Docker data (images, containers, volumes) to the new location.
๐ 7. Validate Copied Data
ll /app/docker/Checks copied data in the new directory.
๐ 8. Configure Docker to Use New Path
cat > /etc/docker/daemon.json{
"data-root": "/app/docker"
}โ 9. Final Configuration:
cat /etc/docker/daemon.json{
"data-root": "/app/docker"
}โถ๏ธ 10. Move Older configuration to backup folder
sudo mv /var/lib/docker /var/lib/docker.bakRestarts Docker with the new configuration.
โถ๏ธ 11. Start Docker Service
sudo systemctl start dockerRestarts Docker with the new configuration.
โ 11. Verify New Docker Root Directory (After Change)
docker info | grep "Docker Root Dir"Confirms Docker is now using /app/docker.
๐๏ธ 12. Cleanup Old Backup (Optional)
sudo rm -rf /var/lib/docker.bakRemoves old Docker data after successful migration.
๐ง Key Notes
- Always stop Docker before copying data to avoid corruption.
- Ensure correct JSON formatting in
daemon.json. - Verify before deleting old data.
/appis ideal due to significantly larger available space.