Monday, 7 September 2015

Change docker default storage location




One of the first tasks I wanted to do after installing Docker on Arch Linux was to be change the default partition storage location. The default location is /var/lib/docker which is the path docker uses as the root of the docker runtime.

Looking at the man pages for docker its not amazingly obvious at first which option needs to be configured but after some research I found it is :

-g, --graph=""

And the service status shows this option is not set by default

$ sudo systemctl status docker
* docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2015-09-07 13:07:10 PDT; 2h 0min ago
     Docs: https://docs.docker.com
 Main PID: 420 (docker)
   CGroup: /system.slice/docker.service
           `-420 /usr/bin/docker daemon -H fd://

Its possible to define --graph within the /usr/lib/systemd/system/docker.service file but this will be overwritten with every new release of docker.

The solution is first create a directory:

$ sudo mkdir /etc/systemd/system/docker.service.d

Then create a file similar to the following

$ cat /etc/systemd/system/docker.service.d/dockerruntimeroot.conf
[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// --graph /mnt/docker-data


Then

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker


Now the new path will be shown in the service status

$ systemctl status docker
* docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/docker.service.d
           `-dockerruntimeroot.conf
   Active: active (running) since Mon 2015-09-07 15:52:28 PDT; 1min 49s ago
     Docs: https://docs.docker.com
 Main PID: 8981 (docker)
   CGroup: /system.slice/docker.service
           `-8981 /usr/bin/docker daemon -H fd:// --graph /mnt/docker-data

No comments:

Post a Comment