Skip to content

Instantly share code, notes, and snippets.

@hitorilabs
Last active April 30, 2024 03:13
Show Gist options
  • Save hitorilabs/92f370dacb6e0b0008a869ff0d2ec157 to your computer and use it in GitHub Desktop.
Save hitorilabs/92f370dacb6e0b0008a869ff0d2ec157 to your computer and use it in GitHub Desktop.

Move the default Docker data-root

One situation that seems pretty common that is making a small partition for the root directory and allocated the rest of your memory for your home directory.

The default data-root is in /var/lib/docker/ - my solution is just to move all the files in this directory to /home with the same permissions and what not.


All you have to do is stop docker processes and the service sudo systemctl stop docker

For specifying data-root, you have some options:

  1. You can add an entry to /etc/docker/daemon.json (recommended, you will already have this file if you install nvidia-ctk
{ 
   "data-root": "/home/docker",
   ...
}
  1. Or you can edit /lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -g /home/docker -H fd:// --containerd=/run/containerd/containerd.sock

Then, copy the files over rsync -avxP /var/lib/docker /home

Now, restart the service and you should be good to go.

sudo systemctl restart docker

Then finally you can get rid of the replicated data in /var/lib/docker


To double check if it's working, try running a container and doing docker inspect <container> and you should see references to /home/docker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment