Skip to content

Instantly share code, notes, and snippets.

@mohamad-supangat
Created June 5, 2023 02:13
Show Gist options
  • Save mohamad-supangat/dff32c3db33002f79c33ca999cceacc9 to your computer and use it in GitHub Desktop.
Save mohamad-supangat/dff32c3db33002f79c33ca999cceacc9 to your computer and use it in GitHub Desktop.
Change /var/lib/docker folder

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 cp -axT /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:

sudo docker images

The previous answer:

Uses an obsolete/undocumented(?) option -g. Instead you should use the option documented in dockerd --help, which is --data-root.
Edits the service file, which might cause problems when installing updates. Instead you should edit /etc/docker/daemon.json.
Uses rsync to copy files without preserving ACLs, xattrs and hard links, though I’m not sure there’s any.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment