I'm new to Docker and I was playing around with docker volume
. I wanted to specify the location where docker volume
stores the data. Much like when we provide the -v
option when we execute docker run
. Ex : -v /somefolder/:/var/somefolder
How can we set a custom Mountpoint when we create a docker volume
. I didn't find any options on docs.
When I inspect the volume
[
{
"Name": "sampleproject_mysql_data",
"Driver": "local",
"Mountpoint": "/mnt/sda1/var/lib/docker/volumes/sampleproject_mysql_data/_data",
"Labels": null,
"Scope": "local"
}
]
I get something like above.
If you need a named volume that's pointing to a host filesystem location (which is a bit of reinventing the wheel since you can do a host mount, but there appear to be a lot of people asking for it), there's the local persist filesystem driver. This is included in Docker's list of plugins.
Update: It's also possible to do a bind mount with a named volume to any directory on the host using the default local volume driver. This allows you to take advantage of automatic initialization of named volumes, which is missing from host volumes, but has the one downside that docker doesn't create the host directory if it is missing (instead the volume mount would fail). Here are a few ways you can create this named volume: