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.
Description=Docker Application Container Engine
After=network-online.target 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 has been deprecated in v17.05.0 .You can use data-root instead.
To check the other deprecated features: https://docs.docker.com/engine/deprecated/
(Special thanks to Nick Palmius for the update)