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.

There are two ways :

  • You can add the missing variable to the systemd script in /lib/systemd/system/docker.service file like the following.
Description=Docker Application Container Engine
Documentation= docker.socket firewalld.service
ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS
ExecReload=/bin/kill -s HUP $MAINPID
  • 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",

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

"data-root": "/mnt/docker",

To check the other deprecated features:

(Special thanks to Nick Palmius for the update)

Developer Space

Tech Blog

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store