I'm using docker version 18.09.2, build 6247962
.
I run a container and mounted a host directory to the container.
docker run -it -p 4444:8000 -v c:/py:/azima 27b4b21eeb64 /bin/sh
This created a container and the host directory c:/py
has been mounted to /azima
.
I can check, create, read files and it is working.
But from another powershell
when I run this command docker volume ls
.
This shows empty.
Inspecting the container
gives this info (if this helps):
"Mounts": [
{
"Type": "bind",
"Source": "/host_mnt/c/py",
"Destination": "/azima",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
Why is the volume not listed?
This is because -v c:/py:/azima
option will mount c:/py
onto /azima
directory inside container using bind-mounts.
Bind mounts are basically just binding a certain directory or file from the host inside the container, which you did.
That's why when you inspect the container you see "Type": "bind"
Whereas docker volume will create Named volumes which you create manually with docker volume create VOLUME_NAME
. They are created in /var/lib/docker/volumes
and can be referenced to by only their name.
These named volumes where only get listed in docker volume ls command.
And when you inspect container attached to such volume you will see "Type": "volume"
More info here.
Hope this helps.
Docker volume and Docker mount are two different things.
In bind mounts, we specify
Host Path
and it does not show indocker volumes ls
and volume we specify dockervolume name
and we can see docker volume usingdocker 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"
}
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With