How to Change the Default Docker Directory to Save You Some Precious Disk Space

Are you the kind of person that likes to gratuitously partition their hard disk because they’re obsessed with compartmentalisation? Do you think Docker is great but it’s eating up all of your /var or / space? Are you sick of manually cleaning up all Docker volumes, images and dangling containers for Docker to fill your disk to the brim with this useful junk within a fortnight? I’ve got an easy solution for you (actually, two). Change the default Docker graph directory! How, do you ask? I’ll show you how.

Docker stores most of its runtime files (graph data, images, runtimes, temp files and much more) in /var/lib/docker by default. But I don’t want that, because my /var partition is just 10 GiB and Docker can easily gobble all of that up. I don’t mind storing these files in my own home directory instead so that’s what I’m going to do.

$ mkdir -p /home/dvejmz/var/lib/docker

Now, there are two ways (perhaps more, depends on how much free time you have) in which you can relocate your Docker files: the old way and the new way. The old way simply edits the startup flags passed to the Docker daemon when invoked as a systemd unit. Something like this

[Service]
ExecStart= 
ExecStart=/usr/bin/dockerd --data-root=/home/dvejmz/var/lib/docker -H fd://

(Credit to Arch Linux Wiki)

The new way, which I recommend since it doesn’t rely on any systemd mechanisms, is editing a JSON file. Newer installations of Docker (such as v18.0 which I’m using at the time of writing this article) will attempt to retrieve their start-up flags from a JSON config file located in /etc/docker/daemon.json, and add the following key to it (if the file doesn’t exist, just create it there):

{
    "graph": "/home/dvejmz/var/lib/docker"
}

The daemon.json file accepts the same options that you may pass to dockerd when launching it. See the official docs for a complete list.

Once you have that, purge all the junk in the old directory.

$ docker rm $(docker ps -a -q)
$ docker rmi $(docker images -q)
$ docker volume rm $(docker volume ls -qf dangling=true)

Now just restart the Docker daemon for the changes to take effect

$ sudo systemctl restart docker

You’re done, enjoy your newly recovered partition space. And by the way, if you’re still lacking in hard disk space after applying this neat trick, check out baobab and bleachbit.

Back to top ↑

Do you have any questions, comments or feedback about this article to share with me or the world?

You can message me on Mastodon. You can also reach out to me in a couple of other ways, if you'd prefer. I would love to hear your thoughts either way!

Articles from friends and people I find interesting

Very Nice Idea

Hello, loves! Better yet, it will involve actual programming! Let’s improve the Making App. My brother GeePaw Hill refers to the Making App and the Shipping App as aspects of a software product. The Shipping App is, of course, the bits …

via ronjeffries.com September 12, 2026

It took a year to ship WebAssembly in Anubis

After a year of work, hundreds of commits, 5 generations of pull requests, dozens of tests, rewriting part of Anubis in Rust, the first compiler bug of my career, and at least three times making my tower run out of ram I think I have final…

via Xe Iaso's blog September 6, 2026

AI in Linux

The role of AI tools (LLMs, mainly) in Linux is under discussion, or it was, until Linus Torvalds “put his foot down” in support of the use of AI in Linux kernel development.I can identify two major ways in which AI is used for Linux kernel deve…

via Drew DeVault's blog July 23, 2026

Generated by openring