Tip: change the directory of installation of Docker (Ubuntu/Debian)

The solution presented here is resumed from the one offers by the LinuxConfig.org site. It tells you how to migrate the file of installation by default of Docker (that is generally /var/lib/docker) towards an other file on your machine. A reason that may motivate this operation is the lack of space on the current disk place. The file /var/lib/ being  generally on the root partition of your system, it is always delicate to extend that partition the a trivial way. According to the original article, that would have to work for all Ubuntu or Debian system. That solution has been tested with care by us  successfully on Ubuntu 16.04 and Docker 17.03. We do not ensure that it works under other environments.

First and foremost, ensure to stop all your current in progress containers actuels. Throughout this migration, neither one of your images of your containers will be removed. You may however do a backup of containers if you perfer to defend against any risk.

Start by opening a session in sudo way. Then, modify with your favorite text editor the systemd /lib/systemd/system/docker.service script that is launched art the sytem startup. In command line, the utilitarien as vi or nano will effectively fit the bill. Locate the following line:

ExecStart=/usr/bin/docker daemon -H fd://

Edit that line to add the -g option with the way of the new directory.

ExecStart=/usr/bin/docker daemon -g /new/path/docker -H fd://

Replacer /new/path/docker with the absolute path of the destination file that you wish. Save the file, then restart now the Docker demon:

systemctl stop docker

It is very significant that the Docker demon would be completely stopped. The following command has to produce no output if the demon is properly stopped!

ps aux | grep -i docker | grep -v grep

If no output is produced by that command, reload the Docker demon with the following command:

systemctl daemon-reload

Once it is done, you have to create the new Docker directory and synchronize your current with the rsync command:

mkdir /new/path/docker
rsync -aqxP /var/lib/docker/ /new/path/docker

The /var/lib/docker file of the command bellow is to replace with the current file of Docker installation. It is the default file, unless you already have done a migration. You may now start the Docker demon:

systemctl start docker

Run that command to check that the Docker demon is launched with the new -g option:

ps aux | grep -i docker | grep -v grep
root      2095  0.2  0.4 664472 36176 ?        Ssl  18:14   0:00 /usr/bin/docker daemon -g  /new/path/docker -H fd://
root      2100  0.0  0.1 360300 10444 ?        Ssl  18:14   0:00 docker-containerd -l /var/run/docker/libcontainerd/docker-containerd.sock --runtime docker-runc

 

 

Was this article helpful?
6 out of 7 found this helpful

Comments

0 comments

Please sign in to leave a comment.