Member-only story

How to change docker root data directory and why would you want to do that (hint: to optimize space)

This article provides a guide on how to change Docker’s root data directory to a new volume on a VPS,

Diego Carrasco G.
2 min readNov 23, 2023

I have a small vps for some personal projects which has 20 gb storage. I have one project there, and a few day ago I no longer had any available space. That meant docker services went down (and so the small project). I knew the project should not use that much space, and I found out that docker was using around 10gb space for overlay2.

The whole overlay2 situation is enough for another post, but I found out (after researching and reading a lot of articles) that it grows pretty fast, and it is really hard to clean. òverlay2 is one of the ways docker synchronizes the filesystem, and it duplicates data.

I decided to change the root data directory (by default at /var/lib/docker) to another volume attached to my vps, which I can increase in space if needed.

Steps

Important:

Make a backup of all your information (volumes, containers and everything that you cannot automatically generate again.)

1. Stop docker service

sudo systemctl stop docker

on older systems

2. Edit etc/docker/daemon.json or create it if it does…

--

--

Diego Carrasco G.
Diego Carrasco G.

Written by Diego Carrasco G.

Hi, I'm an entrepreneur-turned-developer living in Germany. I enjoy learning, write, coffee and solving problems. I write mainly about technology.

No responses yet