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
Thanks for that
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.
Hi Niels,
don’t let permission errors stop you! Permissions is an important concept and you will have those again and again. Just read up on how they work and then fix them. It is not difficult.
https://www.linux.com/training-tutorials/understanding-linux-file-permissions/
Thank you. This got me out of some trouble this morning.
Thanks so much, that worked for me 🙂