What volumes belongs to what Container

Hello,
I have a few container and volumes, how can I know what volumes belong to what container?

thanks.

hey

use docker inspect <container name or id>
then check Mounts section, it contains all the volume attached to that container

Hello,

This is the info I get

},
“Mounts”: ,
“Config”: {
“Hostname”: “6282d7693e03”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: true,
“AttachStdout”: true,
“AttachStderr”: true,
“Tty”: true,
“OpenStdin”: true,
“StdinOnce”: true,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”
],
“Cmd”: [
“/bin/bash”
],
“Image”: “max.v3”,
“Volumes”: null,
“WorkingDir”: “”,
“Entrypoint”: null,
“OnBuild”: null,
“Labels”: {
“build-date”: “20161214”,

            "license": "GPLv2",
            "name": "CentOS Base Image",
            "vendor": "CentOS"
        }

sudo docker volume list
DRIVER VOLUME NAME
local 45f231398741c24982db2db0061cb202ec6ac07229d63e7261a6ed987698872c
local 556d23b33ee2862af7bae27939e08445ac2d38898d02f74eb838c79f7539435c
local 582eae6c59c18b16ce5228d71be088171c3aaaa70ef28a4b0fd5fe39457ade68
local dbf84dd0f1242078ced712fe4d2a8620667c4304e74ef80bb2df2780efd7ad6b
local e55f8b5d5313041adf7fd381da24934c648518538b393272d90a19714111d731

1 Like

hey
Mounts section should show like below if anything attached
Mounts: [ { "Type": "volume", "Name": "c04f04a571d3e44ec6d6b5f89641f4f518a30c80916e026e8f18b7616165f2e8", "Source": "/var/lib/docker/volumes/c04f04a571d3e44ec6d6b5f89641f4f518a30c80916e026e8f18b7616165f2e8/_data", "Destination": "/data", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } ]

if not that means no volume is attached

1 Like

Thanks.!!! I will try to understand a little more about this.

1 Like

welcome :+1:
please do post if you find interesting.

The following snippet will tell you the IP of a container. Use the same logic to get details about the volume

docker inspect -f ‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ CONTAINER_NAME_OR_ID

1 Like