๐Ÿณ 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 ps

Lists running containers to confirm Docker activity.

systemctl status docker

Checks 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.json

Displays current Docker configuration (if present).


โ›” 4. Stop Docker Service

sudo systemctl stop docker

Stops Docker to safely modify its data directory.


๐Ÿ“ 5. Create New Data Directory

sudo mkdir -p /app

Creates the target directory for Docker storage.

sudo chown -R root:root /app

Ensures 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.bak

Restarts Docker with the new configuration.


โ–ถ๏ธ 11. Start Docker Service

sudo systemctl start docker

Restarts 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.bak

Removes 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.
  • /app is ideal due to significantly larger available space.