Skip to content

Instantly share code, notes, and snippets.

@franciscocpg
Last active July 18, 2023 12:56
Show Gist options
  • Save franciscocpg/ac952d1070b16f4f56b3d141e035c9ee to your computer and use it in GitHub Desktop.
Save franciscocpg/ac952d1070b16f4f56b3d141e035c9ee to your computer and use it in GitHub Desktop.
How to move the default /var/lib/docker to another directory for Docker on Linux

Take note that you can use this approach to move the /var/lib/docker directory to another disk or partition. Just make sure you create the destination directory in this new disk or partition.

  • Stop the server:
sudo systemctl stop docker
  • Create/edit the configuration at /etc/docker/daemon.json, for example:
{
  "data-root": "/new/path/docker-data-root"
}
  • Copy your data there:
sudo mkdir /new/path/
sudo rsync -avxP /var/lib/docker /new/path/docker-data-root

(if the target docker-data-root directory already exists, make sure you don’t accidentally copy into a docker subdirectory).

  • Start the server:
sudo systemctl start docker
  • Check everything works:
docker run hello-world
  • When you ensure that everything is working fine, you can remove data from the old directory:
sudo rm -rf /var/lib/docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment