DEV Community

Camille
Camille

Posted on

Move docker volume to another disk

Docker volumes are essentially directories on the host filesystem, so moving them involves copying data and updating references.
Here’s a high-level guide to move a Docker volume to another disk:

1. Find the volume location

Docker stores volumes (by default) in:
/var/lib/docker/volumes/<volume_name>/_data

You can find the volume's mount point like this:

docker inspect <container_name>
docker volume inspect <volume_name>
Enter fullscreen mode Exit fullscreen mode

Look for the Mountpoint field.

2. Stop the containers using the volume

This is important to avoid data corruption.

docker ps
docker stop <container_name>
Enter fullscreen mode Exit fullscreen mode

3. Copy the volume data to the new disk

Let’s say you want to move it to /mnt/newdisk/docker-volumes/

sudo rsync -aP /var/lib/docker/volumes/<volume_name>/_data/ /mnt/newdisk/docker-volumes/<volume_name>/
Enter fullscreen mode Exit fullscreen mode

Make sure /mnt/newdisk is mounted and accessible.

  1. Bind-mount the new location Instead of using the Docker-managed volume, you can use a bind mount that points to the new location: When running the container, use:
docker run -v /mnt/newdisk/docker-volumes/<volume_name>:/data <image>
Enter fullscreen mode Exit fullscreen mode

Or update your docker-compose.yml:

volumes:
  mydata:
    driver: local
    driver_opts:
      type: none
      device: /mnt/newdisk/docker-volumes/mydata
      o: bind
Enter fullscreen mode Exit fullscreen mode

Then redeploy with:

docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

Optional: Remove the old volume
Only do this once you're 100% sure the move was successful:

docker volume rm <volume_name>
Enter fullscreen mode Exit fullscreen mode

Let me know your setup (e.g., docker-compose, named volumes, etc.) if you want help crafting exact commands or config.

Top comments (0)