How to change the default data/image directory of docker?

Changing data/image location – Docker.

Well, in some low disk host you may prefer a better, large partition for your Docker base directory. Once you installed Docker, the default data directory is “/var/lib/docker.”

It contains all the data for your docker installation, like all the docker images your built or pulled from the hub.

Common directories under /var/lib/docker

drwx------  2 root root 4096 Jan 22 22:08 builder/
drwx--x--x  3 root root 4096 Jan 22 22:08 containerd/
drwx------  5 root root 4096 Jan 23 05:47 containers/
drwx------  3 root root 4096 Jan 22 22:08 image/
drwxr-x---  3 root root 4096 Jan 22 22:08 network/
drwx------ 15 root root 4096 Jan 23 05:49 overlay2/
drwx------  4 root root 4096 Jan 22 22:08 plugins/
drwx------  2 root root 4096 Jan 23 05:46 runtimes/
drwx------  2 root root 4096 Jan 22 22:08 swarm/
drwx------  2 root root 4096 Jan 23 05:49 tmp/
drwx------  2 root root 4096 Jan 22 22:08 trust/
drwx------  2 root root 4096 Jan 22 22:08 volumes/

Steps to change the default location.

Step 1. Stop docker daemon.

/etc/init.d/docker stop

Step 2. Make sure that there are no docker related processes.

ps aux|grep docker

Step 3. Move the contents of /var/lib/docker to your new location.

mv /var/lib/docker /home/

Step 4. Create a softlink to default location.

ln -s /home/docker/ /var/lib/docker

Step 5. Start docker daemon.

/etc/init.d/docker start

Step 6. Make sure all the images and data are working from the new location.

That’s it!

1. An introduction note to Docker containers – basics, part 1
2. Managing Docker containers – basics, part 2

Post navigation

Arunlal A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

5 thoughts on “How to change the default data/image directory of docker?

  1. Hi Arun,

    These instructions didn’t work for me. I followed the steps, but I got a permission error when starting the docker daemon. I’ve now restored everything to the previous situation.

    My setup is docker snap, maybe that’s differtent. I will need to look for an alternative solution.

Leave a Reply

Your email address will not be published. Required fields are marked *