How to change the default location for "docker create volume" command?

Solution 1:

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:

# Old - taken from the generated docker.service file in Ubuntu 16.04's docker.io package
ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS

# New
ExecStart=/usr/bin/dockerd --data-root /new_location/ -H fd:// $DOCKER_OPTS

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.

Solution 2:

2017: with 17.05.0-ce (2017-05-04), the PR 28696 deprecates --graph flag in favor or --data-root: commit 1ecaed0

The name "graph" is a legacy term from long ago when there used to be a directory at the default location /var/lib/docker/graph.

However, the flag would indicate the path of the parent directory of the "graph" directory which contains not only image data but also data for volumes, containers, and networks.
In the most recent version of docker, this directory also contains swarm cluster state and node certificates.

With issue 5922 and PR 5978, the documentation has been updated.

Example:

ExecStart=/usr/bin/dockerd -H fd:// --data-root=/mnt/ssd/lib/docker

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":

Docker supports softlinks for the Docker data directory (/var/lib/docker) and for /var/lib/docker/tmp.
The DOCKER_TMPDIR and the data directory can be set like this:

DOCKER_TMPDIR=/mnt/disk2/tmp /usr/local/bin/docker daemon -D -g /var/lib/docker -H unix:// > /var/lib/docker-machine/docker.log 2>&1
# or
export DOCKER_TMPDIR=/mnt/disk2/tmp
/usr/local/bin/docker daemon -D -g /var/lib/docker -H unix:// > /var/lib/docker-machine/docker.log

As mentioned in "Where are docker images stored on the host machine?" (and that would apply also for containers/volumes):

The contents of the /var/lib/docker directory vary depending on the driver Docker is using for storage.