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 Ashok

Operations Engineer at Endurance International Group. Linux lover. Like to play on Linux console. I started this blog to share and discuss Linux thoughts.

Always happy for an open discussion! Write to arun (@) crybit (dot) com. Check about me for more details. About this blog and our strong members, check The team CryBit.com
We like to travel. Our travelogues are published at Trip Mentor

Leave a Reply

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