Docker Community Forums

Share and learn in the Docker community.

Unable to change data directory from /var/lib/docker. Docker version 20.10.7, build f0df350 Ubuntu 20.04

My usage scenario requires too much space for data to be stored in /var/lib/docker so my / (root) partition gets filled and everything goes to hell. I found posts suggesting that changing data-root in /etc/docker/daemon.json solves the problem. I have no such file:

firstuser@claire2:~/Documents$ ls /etc/docker/
key.json

So instead I have attempted to modify the service file…

sudo service docker stop
# Added --data-root option to /etc/init.d/docker below
# DOCKER_OPTS=--data-root /home/docker
# Moved directory to home
sudo mv /var/lib/docker  /home
sudo  systemctl daemon-reload
sudo service docker start

The restarted docker service created a new /var/lib/docker :frowning: and did not use /home as I wanted.
So undid it all for now hence the comment (#) above for DOCKER_OPTS so not in effect anymore.
:thinking:

I would like someone to show me how I can change this directory so it can be on a bigger non-system partition. If I see no easy way out I may just try a logical link :slight_smile:

Hi

daemon.json is not there by default, you need to create it to override the default configuration, the content of that file should be :

{  "data-root": "/home/docker" }

Solved as a result for your advice. Thank you. I inferred incorrectly that the absence of the file meant that something had changed possibly related to the way the apt package was done or other reasons. I am accustomed to the model of configuration files being there even if they don’t have much in them. Regards