Docker Community Forums

Share and learn in the Docker community.

Change volumes only location


I would like to move Docker volumes only to a persistent partition (say /data) and let other Docker data such as images in the default partition (/var/lib/docker).

I know that using the option --dataroot in the docker.service file would change the location of /var/lib/docker. But is it possible to change volumes location only?


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 package

ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS


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.

Thank you.

However, this method would move the entire Docker directory no ? I mean it would not only move volumes but also where the images and other Docker stuff is stored ?