How to find volumes that can be mounted in a docker container

You can find what can be mounted by inspected the container.

sudo docker container inspect my-container

This will give you a json output (much longer than this output)

{
  "Id": "47eca95e3dfa40eac6fd6c2c03fec8cfb45d813a8e0af684de60d5292978e172",
  "Created": "2018-11-24T15:56:47.673723654Z",
  "Path": "docker-entrypoint.sh",
  "Args": [
    "redis-server"
  ],
  "State": { },
  "Config": {
    "ExposedPorts": {
      "6379/tcp": {}
    },
    "Volumes": {
      "/data": {}
    }
  }
}

You can access easily with jq like this :

sudo docker container inspect my-redis | jq '.[0].Config.Volumes'

This will give you the following output :

{
  "/data": {}
}

The result of the mounted volume will be shown with the following :

sudo docker container inspect my-redis | jq '.[0].Mounts'

Output :

[
  {
    "Type": "volume",
    "Name": "9b2d74cffcd195979e50c7583084fbf6b18054ff1e2b8c8e5a53ff34bea5d83b",
    "Source": "/var/snap/docker/common/var-lib-docker/volumes/9b2d74cffcd195979e50c7583084fbf6b18054ff1e2b8c8e5a53ff34bea5d83b/_data",
    "Destination": "/data",
    "Driver": "local",
    "Mode": "",
    "RW": true,
    "Propagation": ""
  }
]
comments powered by Disqus