Docker volume and Docker mount are two different things.
In bind mounts, we specify Host Path
and it does not show in docker volumes ls
and volume we specify docker volume name
and we can see docker volume using docker volumes ls
Volumes: Volumes are the preferred way to store persistent data Docker containers create or use. The host filesystem also stores volumes, similar to bind mounts. However, Docker completely manages them and stores them under ~/docker/volumes by default.
docker volume create alpine_test
Now run the container
docker run --rm -v alpine_test:/root alpine ash -c "touch /root/test.txt"
This will just create a file using volume alpine_test
and the container will terminate.
Now if we run another container and list file
docker run -v alpine_test:/root alpine ash -c "ls /root/"
Still, we are able to see our last created file.
If the container is terminated the data still persists in the volume and available for later use.
If you inspect the volume attached container, It will show the docker volume path
docker inspect container_id
"Mounts": [
{
"Type": "volume",
"Name": "alpine_test",
"Source": "/var/snap/docker/common/var-lib-docker/volumes/alpine_test/_data",
"Destination": "/root",
"Driver": "local",
"Mode": "z",
"RW": true,
"Propagation": ""
}
],

Bind mounts: A bind mount is a file or folder stored anywhere on the container host filesystem, mounted into a running container. The main difference a bind mount has from a volume is that since it can exist anywhere on the host filesystem, processes outside of Docker can also modify it.
docker run -v /home/test/:/test -it --rm alpine
For mount, if you inspect the container you will the host mount path location.
docker inspect container_id
"Mounts": [
{
"Type": "bind",
"Source": "/home/test/",
"Destination": "/root",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],