When creating volumes through the volume API, that is, as the container volume pattern is now not necessarily the best practice anymore:
# docker volume inspect test-data
[
{
"Name": "test-data",
"Driver": "local",
"Mountpoint": "/var/lib/docker/volumes/test-data/_data"
}
]
I would like to, for example, have docker volumes exist in /data (which is mounted in a different physical volume).
This is not possible to do with symbolic links, it is possible to do with bind mounts, but would I'm wondering if there is some configuration in Docker to change the default location for each separate volume.
2017: with 17.05.0-ce (2017-05-04), the PR 28696 deprecates
--graph
flag in favor or--data-root
: commit 1ecaed0With issue 5922 and PR 5978, the documentation has been updated.
Example:
2016 (now deprecated)
I only know of a docker option to change
/var/lib/docker
itself, not its subfolders (part of its "graph" used by a docker daemon storage driver)See docker daemon "Miscellaneous options":
As mentioned in "Where are docker images stored on the host machine?" (and that would apply also for containers/volumes):
I successfully moved the storage location of docker by moving the content of /var/lib/docker to a new location and then place a symlink pointing to the new location (I took this solution from here https://askubuntu.com/questions/631450/change-data-directory-of-docker):
Worked for me on Ubuntu 18.04.1 LTS on an Azure VM with Docker 18.09.2
You can change where Docker stores its files including volumes by changing one of its startup parameters called
--data-root
.If you're using systemd for service management, the file is usually located at
/lib/systemd/system/docker.service
. Edit the file as such:Alternatively, you can edit the Docker daemon configuration file which defaults to
/etc/docker/daemon.json
.Restart the Docker daemon and your volumes will be under
/new_location/volumes/{volume_name}/_data
Note: be careful in production and also locally! You also have to move the existing data from
/var/lib/docker/
to the new location for your docker install to work as expected.You can use symlinks from the new location if you want specific folders to be in specific place.