I'm trying to learn docker at the moment and I'm getting confused about where data volumes actually exist.
I'm using Docker for windows. (Windows 10)
In the docs they say that running docker inspect on the object will give you the source:https://docs.docker.com/engine/tutorials/dockervolumes/#locating-a-volume
$ docker inspect web
"Mounts": [
{
"Name": "fac362...80535",
"Source": "/var/lib/docker/volumes/fac362...80535/_data",
"Destination": "/webapp",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
]
however I don't see this, I get the following:
$ docker inspect blog_postgres-data
[
{
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/blog_postgres-data/_data",
"Name": "blog_postgres-data",
"Options": {},
"Scope": "local"
}
]
Can anyone help me? I just want to know where my data volume actually exists is it on my host machine? If so how can i get the path to it?
Thanks
Each container has its own filesystem which is independent from the host filesystem. If you run your container with the -v flag you can mount volumes so that the host and container see the same data (as in docker run -v hostFolder:containerFolder).
The first output you printed describes such a mounted volume (hence mounts) where "/var/lib/docker/volumes/fac362...80535/_data" (host) is mounted to "/webapp" (container).
I assume you did not use -v hence the folder is not mounted and only accessible in the container filesystem which you can find in "/var/lib/docker/volumes/blog_postgres-data/_data". This data will be deleted if you remove the container (docker -rm) so it might be a good idea to mount the folder.
As to the question where you can access this data from windows. As far as I know, docker for windows uses the bash subsystem in Windows 10. I would try to run bash for windows10 and go to that folder or find out how to access the linux folders from windows 10. Check this page for a FAQ on the linux subsystem in windows 10.
Update: You can also use docker cp to copy files between host and container.
Your volume directory is
/var/lib/docker/volumes/blog_postgres-data/_data
, and/var/lib/docker
usually mounted onC:\Users\Public\Documents\Hyper-V\Virtual hard disks
, anyway you can check it out by looking docker settings.You can refer to this docs for info of how to share drives with docker on windows.
BTW,
Source
is the location on the host andDestination
is the location inside container in the following output:===========================================================================
Updated to answer questions in the comment:
Actually
volume
is designed for this purpose(manage data in docker container), the data in volume is persisted on host FS and isolated with the life-circle of docker container/image. You can share your data with volume by:Mount docker volume to host and reuse it
docker run -v /path/on/host:/path/inside/container image
Then all your data will persisted in
/path/on/host
, you could backup it, copy it to other machine and re-run your container with the same volume.Create and mount a data container.
Create data container:
docker create -v /dbdata --name dbstore training/postgres /bin/true
Run other container based on this container using--volumes-from
:docker run -d --volumes-from dbstore --name db1 training/postgres
, then all data generated bydb1
will persisted in the volume of containerdbstore
.For more information you could refer to official docs of docker volumes, simply speaking,
volumes
is just a directory on your host with all your container data, so you could use any methods you used before to backup/share your data.No, docker image is something you deliver, but data is not. You could backup/persist/share your data with any method you like, but pushing data to docker registry to share it does not make any sense.
Yes, as posted above :-)