Search code examples
dockerdocker-volume

docker volume ls lists empty


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?


Solution

  • 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.