Docker - Set Docker root directory using root-data in daemon.json

by
Jeremy Canfield |
Updated: October 19 2023
| Docker articles
By default, the root directory for Docker is typically /var/lib/docker.
~]$ sudo ls -l /var/lib/docker
total 24
drwx--x--x. 4 root root 120 Aug 27 2021 buildkit
drwx--x--x. 3 root root 20 Aug 27 2021 containerd
drwx--x---. 7 root root 4096 Oct 16 06:00 containers
drwx------. 3 root root 22 Aug 27 2021 image
drwxr-x---. 3 root root 19 Aug 27 2021 network
drwx--x---. 81 root root 12288 Oct 19 04:44 overlay2
drwx------. 4 root root 32 Aug 27 2021 plugins
drwx------ 2 root root 6 Oct 19 04:44 runtimes
drwx------. 2 root root 6 Aug 27 2021 swarm
drwx------ 2 root root 6 Oct 19 04:44 tmp
drwx------. 2 root root 6 Aug 27 2021 trust
drwx-----x. 7 root root 4096 Oct 19 04:44 volumes
This can be changed by setting data-root in /etc/docker/daemon.json. If this JSON file does not exist, you can simply create it.
{
"data-root": "/path/to/directory"
}
And then reload the system daemons.
systemctl daemon-reload
And restart the Docker service.
systemctl restart docker
A bunch of default Docker files and directories will be created in whatever directory you set for data-root. This is actually a great way to test something without impacting your "normal" docker install and then when done testing, simply remove data-root from daemon.json, reload the daemon, restart Docker, remove the temporary directory, and you'll be back to your "normal" Docker install.
~]$ sudo ls -l /tmp/dockertmp
total 4
drwx--x--x+ 4 root root 148 Oct 19 05:39 buildkit
drwx--x--x+ 3 root root 28 Oct 19 05:39 containerd
drwx--x---+ 2 root root 10 Oct 19 05:39 containers
drwx------+ 3 root root 30 Oct 19 05:39 image
drwxr-x---+ 3 root root 27 Oct 19 05:39 network
drwx--x---+ 7 root root 4096 Oct 19 05:43 overlay2
drwx------+ 4 root root 44 Oct 19 05:39 plugins
drwx------+ 2 root root 10 Oct 19 05:39 runtimes
drwx------+ 2 root root 10 Oct 19 05:39 swarm
drwx------+ 2 root root 10 Oct 19 05:44 tmp
drwx------+ 2 root root 10 Oct 19 05:39 trust
drwx-----x+ 2 root root 62 Oct 19 05:39 volumes
Did you find this article helpful?
If so, consider buying me a coffee over at