How to move the base docker directory to another location

Some weeks ago, I started getting notices that the root dir where my Linux is mounted was getting low space. I dismissed the warnings and thought there should be something out of the way. Still true that my Linux root partition is just  85 gigs, because I repartitioned the disk on a laptop that goot only Windows installed in it, and Ubuntu does not need that much space in order to install the core of its OS, keeping my /home on a separate partition in case had to reinstall Linux and all my personal stuff in a NTFS partition shared between Windows and Linux. I emptied all the trash folders, clean the /tmp  dir completely and still was getting the warnings.


Even I installed a program named bleachbit does all the house-cleaning work of your Linux for you. Even after using all their available cleaning options still keep to get warnings about low space on the root partition. What the hell was happening !? Then I made a du -h / --max-depth=10 to get the complete space occupied by each subdirectory. I got something like 60 GB in the /var directory. And inside the /var/lib/ the majority of those 60 GB belonged to the /var/lib/docker !
Then I remembered that some months ago, I created a cron task to update a docker image of my VPS locally to a docker image. The problem was, each day that task run and each day stored at least more 1 GB in the root partition. Had to remove (or in better words, commented the text line containing the task on crontab file) until I could find a way in which to store the huge docker image that was filling up my root partition.
Happens that I own a NAS, so the logical question was, will be possible to move the /var/lib/docker to a shared directory in my nas. I googled and found that is possible to move that directory to another, just add to change the ‘/etc/default/docker‘ with : “DOCKER_OPTS='-g /another_place'” .

So I copied all the directory contents into the new shared directory on my NAS. First I used the SMB/CIFS protocol, but started to get problems after trying to start the docker service. The docker service was struggling with creating new files and didn’t have the problems. I switch from CIFS to NFS and now the service docker started without errors. Another thing was starting a new container with the image now residing on a remote directory mounted locally. Got some errors and after launching the rsync script to sync with my VPS. Now next step will be to squeeze all layers on the docker image to one in order to reclaim wasted space. The question of heart to remember is that to use docker on a regular basis you need lots of space if dealing with lots of images. Still I’m unsure if using one container with one big image rsync-ed from my VPS is still the best solution for the fact that my VPS hosting service don’t provide me with backups.

 

Leave a Reply