2

This question asks about listing volumes in containers.

But what I'm looking for here is, how do you find volumes configured into an image itself, without creating a container first?

The idea is, I want to know what an image might do with volumes mapped to the host file system, before allowing a container to run from that image.

The official postgres image is a good example. When you start a container of this image, it automatically creates a volume at /var/lib/postgresql/data. Is there a way to figure that out before starting a container?

Community
  • 1
  • 1
CivFan
  • 13,560
  • 9
  • 41
  • 58

1 Answers1

5

Sure. You can use the docker inspect command on the image. For example:

$ docker inspect postgres
[...]
        "Volumes": {
            "/var/lib/postgresql/data": {}
        },
[...]

If you want to avoid all the other output, you can use:

$ docker inspect --format '{{.ContainerConfig.Volumes}}' postgres
map[/var/lib/postgresql/data:{}]
larsks
  • 277,717
  • 41
  • 399
  • 399
  • If you want to use the output in scripts, its possible to output an array with a little more work (sorry, dont know how to do formatting in comments): `docker inspect --format='{{range $a, $b := .Config.Volumes }}{{ printf "\"%s\" " $a }}{{end}}' postgres` Output: `"/var/lib/postgresql/data" ` – Norbert Lange Jan 14 '16 at 11:17