Change Docker Root Directory location.

In this post i am going to show you how to find the Docker Root Directory and how to change the location so that docker can save the files in some other location (For Backup or High Availability).

This is the commands to find and verify the Docker Root Folder.

root@master:~# docker info | grep -i root
 Docker Root Dir: /var/lib/docker

root@master:~# sudo du -sh /var/lib/docker/
2.7G    /var/lib/docker/

root@master:~# cd /var/lib/docker/
root@master:/var/lib/docker# ll
total 56
drwx--x--x 14 root root 4096 Nov 16 11:31 ./
drwxr-xr-x 40 root root 4096 Nov 16 07:53 ../
drwx------  2 root root 4096 Nov 16 07:53 builder/
drwx--x--x  4 root root 4096 Nov 16 07:53 buildkit/
drwx------  2 root root 4096 Nov 17 12:58 containers/
drwx------  3 root root 4096 Nov 16 07:53 image/
drwxr-x---  3 root root 4096 Nov 16 07:53 network/
drwx------ 46 root root 4096 Nov 17 12:58 overlay2/
drwx------  4 root root 4096 Nov 16 07:53 plugins/
drwx------  2 root root 4096 Nov 16 11:31 runtimes/
drwx------  2 root root 4096 Nov 16 07:53 swarm/
drwx------  2 root root 4096 Nov 17 12:42 tmp/
drwx------  2 root root 4096 Nov 16 07:53 trust/
drwx------ 13 root root 4096 Nov 16 13:41 volumes/

To change the location of the Root Directory

  • Stop all containers
  • Stop the Docker servicer
sudo systemctl stop docker

After all the above was done.We need to enter to the docker config file.

sudo vi /lib/systemd/system/docker.service

Now we need to move the docker folder form his old location to the new one.

root@master:/var/lib/docker# sudo rm -rf /mnt/docker

root@master:/var/lib/docker# ls /mnt/

root@master:/var/lib/docker# mv docker /mnt/

After we moved the folder we need to start the service again.

sudo systemctl restart docker

That’s it you ready to keep using Docker 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.