Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active March 16, 2023 20:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plembo/0070059bde27bb8fb37735a899b16e41 to your computer and use it in GitHub Desktop.
Save plembo/0070059bde27bb8fb37735a899b16e41 to your computer and use it in GitHub Desktop.
Change Docker data directory

Relocate the docker data directory

By default docker on linux uses /var/lib/docker as its data directory (in docker parlance, "data-root"). This can be inconvenient for those of us whose /var is located on a boot drive with only a modest amount of space. After installing docker I always relocate its data directory to a bigger volume. Assuming that volume is named "data1", here's the procedure:

  • Shut down docker and containerd, systemctl stop docker; systemctl stop containerd.
  • Create a /etc/docker/daemon.json file with the following contents:
{
  "data-root": "/data1/docker"
}
  • Use rsync to copy the data from the old to new locations:
rsync -a /var/lib/docker /data1
  • Restart containerd and docker again, systemctl start containerd; systemctl start docker

References:

"Control Docker with systemd". Docker Docs, https://docker-docs.netlify.app/config/daemon/systemd/.

"Relocating the Docker root directory". IBM Z Operational Log and Data Analytics, https://www.ibm.com/docs/en/z-logdata-analytics/5.1.0?topic=compose-relocating-docker-root-directory.

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