How to move docker's default /var/lib/docker to another directory on Ubuntu/Debian Linux - LinuxConfig.org


#1
The following config will guide you through a process of changing the docker's default /var/lib/docker storage disk space to another directory. There are various reasons why you may want to change docker's default directory from which the most obvious could be that ran out of disk space. The following guide should work for both Ubuntu and Debian Linux or any other systemd system. Make sure to follow this guide in the exact order of execution.
This is a companion discussion topic for the original entry at https://linuxconfig.org/how-to-move-docker-s-default-var-lib-docker-to-another-directory-on-ubuntu-debian-linux

#2

mihai

If you start docker and the images are gone and docker tries to fetch others, it’s because of rsync -aqxP /var/lib/docker/ /new/path/docker, normally it creates another docker container in the destination. The command should probably be rsync -aqxP /var/lib/docker/* /new/path/docker. Anyway, I fixed it without re-copying it using : cd /new/path/docker/docker;rm -rf ../{builder,containerd,containers,image,network,overlay2,plugins,runtimes,swarm,tmp,trust,volumes}; mv * ..


#3

Ralms

Didn’t work for me on OpenMediaVault3 running Debian 8
Docker seems to be ignoring all the changes I do :S


#4

Soma Consulting

After I restart server, I don’t see any containers.
so I tried to run rsync -aqxP /var/lib/docker/ /new/path/docker
Then I got the container with previous data and lost all the new update data.
What should I do to get the update data?


#5

Tommy Powell

use daemon.json instead as suggested by kn. I followed the OP directions and the docker.service file got reset after and update.


#6

François-Xavier Michaud

Great, thank you !

You should write :

ps aux | grep -i [d]ocker

to avoid call twice grep


#7

regis25

Altering system scripts is a bad practice when:

  • they’re under a package manager control (s.a. apt): problems on package upgrade
  • the same could be achieved in a less intrusive way, i.e. through a configuration file

In this case, the recommended solution is to create a custom override as per documentation:

https://docs.docker. com/v1.11/engine/reference/commandline/daemon/#daemon-configuration-file


#8

tjenarre

Great, thanks!!!


#9

Arnaud Marchand

Works perfectly. Docker version 17.03.0-ce, build 60ccb22
On ubuntu 16
Thanks for sharing.


#10

kn

Instead of modifying the systemd startup script, one can modify the “-g / --graph” option by adding a /etc/docker/daemon.json with the contents of:

{
“graph”: “/new/path/docker”
}

Other options can also be inserted into that file, e.g. TLS usage


#11

trevi79

Thanks, this worked for me on:

Kernel Version: 4.4.0-62-generic
Operating System: Ubuntu 16.04.1 LTS
OSType: linux
Architecture: x86_64

I had some issues setting the docker root to a non-static mount drive. I used this to set a static mount which solved my problem: http://askubuntu .com/questions/299131/hard-drive-location-keeps-changing-after-upgrade-to-13-04


#12

Martin Goldhahn

Thanks for sharing this one.


#13

I would suggest using this rsync command:

 rsync -aqxHPX --delete /var/lib/docker/ /new/path/docker

-H to ensure hard links are not expanded to duplicate files.
-X for anyone using SELinux to preserve labels