How to change Docker Root Directory location.

Updated: Aug 18

In this post, I am going to show you how you can identify the Docker Root Directory and how you can change the location of the Docker Files so that it saves them in some other location (for backup or for higher availability).


In the following commands, you will be able 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/

 

In order to change the Root Directory's location

  1. Stop all containers

  2. Stop the Docker servicer

sudo systemctl stop docker

 

The next step involves entering the Docker config file after the above steps have been completed.

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

In order to proceed, we must move the Docker folder from the 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/

 

It is necessary to restart the service once we have moved the folder.

sudo systemctl restart docker

 

You are now ready to continue using Docker 🙂



#docker

1 view0 comments