• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Docker | Change Docker Data Directory
By default, Docker store its persisted data (local volumes, containers, filesystem data for images, configuration for resources, swarm cluster state) in /var/lib/docker directory.

To change this location to a new one, edit the file /lib/systemd/system/docker.service and adjust the entry ExecStart.

First, stop Docker service:
$ sudo systemctl stop docker
Adjust /lib/systemd/system/docker.service:
#Before (default location: /var/lib/docker):
#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

#After (new location: /opt/docker)
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --data-root /opt/docker
[Optional] You can copy all your existing Docker data (default location: /var/lib/docker) to the new location (/opt/docker):
$ sudo mv /var/lib/docker /opt/
Reload systemd manager configuration:
$ sudo systemctl daemon-reload
Start Docker service:
$ sudo systemctl start docker
Check the new location:
$ sudo ls -al /opt/docker/
drwx------  2 root   root   4096 builder
drwx--x--x  4 root   root   4096 buildkit
drwx------  2 root   root   4096 containers
drwx------  3 root   root   4096 image
drwxr-x---  3 root   root   4096 network
drwx------  3 root   root   4096 overlay2
drwx------  4 root   root   4096 plugins
drwx------  2 root   root   4096 runtimes
drwx------  2 root   root   4096 swarm
drwx------  2 root   root   4096 tmp
drwx------  2 root   root   4096 trust
drwx------  2 root   root   4096 volumes
© 2025  mtitek