Docker volume ls doesn't show what they are?

When I
docker inspect <container-name>

I see Mounts and in that object I see Destination

but when I want to view this in ls

docker volume ls --format "{{.Name}}: {{.Driver}}: {{.Label "Mounts.Destination"}}"
Template parsing error: template: :1: function "Mounts" not defined

docker volume ls --format "{{.Name}}: {{.Driver}}: {{.Label "project.Mounts.Destination"}}"
Template parsing error: template: :1: function "project" not defined

docker volume ls --format "{{.Name}}: {{.Driver}}: {{.Label "mounts.destination"}}"
Template parsing error: template: :1: function "mounts" not defined

I had created the volume at build in my Dockerfile VOLUME ["bitcoin-data:/home/BTC/data"] should I have done it in a better format or another way to show some indication in ls as to what the volume is? Because these long ids mean nothing to me

I am afraid you got it wrong…

A volume mapping can not be declared in the Dockerfile. You can only mark a path as mount target and flag it as Volume. some management UIs use this information to prepoulate configuration fields.

The mapping you seek to create in your Dockerfile can only be done on container level. E.g. when starting the container with docker run ... -v bitcoin-data:/home/BTC/data or it’s docker compose equivalent.

Note: if a path is marked as VOLUME in a Dockerfile and a container based on the resulting image is started without mapping a volume or a bind to it, an anonymous volume will be created and mounted into the container path. They have random alphanum names and are listed by docker volume ls. That’s why most people stopped declaring VOLUME instructions in their Dockerfiles at all - they can not be undone on container level.

1 Like

I forget to address this part:

In case you are unclear about the required template variables to be used with format, you can use docker volume ls --format "{{json .}}" to see the structure and values in json format.