How To Change Docker Data Folder Configuration

İbrahim Gündüz
May 2, 2018 · 2 min read

From the beginning I would like to say, this not a copy/paste article :)

I would like to mention about it first, because of today I faced the same situation and found too many posts which are copy/pasted and useless :)

Let’s start with WHAT YOU SHOULD NOT DO first:

  • Stop docker service by the following command:
# service docker stop
  • Open the /etc/default/docker file, uncomment the following line and add the new path to DOCKER_OPTS variable like ‘-g /mnt/docker’
  • Start the docker service again by the following command.
# service docker start

And most probably you will see it won’t work, even you rebooted the machine. :)

So you will try the second way which is not clean… Making symlink from the new directory to /var/lib/docker. And you’ll say ‘Thank you it works for me!’

Basically, the issue caused by the initial systemd script, comes with installation. Docker is not aware of your changes because the script doesn’t pass the DOCKER_OPTS variable to the daemon while starting the service.

How To Solve The Issue?

There are two ways :

  • You can add the missing variable to the systemd script in /lib/systemd/system/docker.service file like the following.
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service
Wants=network-online.target
Requires=docker.socket
[Service]
Type=notify
ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
  • Then call the following command to reload the changed configuration: (Special thanks to Daniel Lando for the update)
sudo systemctl daemon-reload
  • Or you can add the new path into /etc/docker/daemon.json file like the following.
{
//...
"graph": "/mnt/docker",
//...
}

Update:

graph has been deprecated in v17.05.0 .You can use data-root instead.

{
//...
"data-root": "/mnt/docker",
//...
}

To check the other deprecated features: https://docs.docker.com/engine/deprecated/

(Special thanks to Nick Palmius for the update)

İbrahim Gündüz

Written by

My Personal Blog

Developer Space

Tech Blog

More From Medium

More on Docker from Developer Space

Also tagged Systemd

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade