How can you see what volumes a container must map for an image and what happens if you don't map it?

Supposed all I have is a docker image, or path to an image, how do I determine what volumes have to be mapped for the image?

And, what happens if I don’t map a volume the image needs?

Read the docker hub description, it should list all environment variables, volumes and other required option to run the container. Also you might want to stay away from images that lack proper documentation. Images from bitnami and linuxserver are usualy a safe bet: well documented, broadly used and frequently updated using ci build chaines.

If a VOLUME declaration is present in a Dockerfile and you don’t map a volume to its target folder, you will end up having anonymous volumes with random alphanumeric names. Check the output of docker volume ls. Afair anonymous volumes are attache to the lifecycle of a container: created with them, removed with them (though, not 100% sure about the last bit, as sometimes you will find orphaned anyonymous volumes).

Use named volumes (e.g. for remote shares, but can be local folders as well) or bind-mounts (local folders only) if you want/need to persist data.

What about if they are not in DockerHub or a central place like that? I know I shouldn’t trust them but let’s just say I have the image – is there any other way to check? Like a way to reverse engineer the DockerFile?

The idea is to look at an image and see what is exposed – what needs to be mapped.

You might want to check the output of docker history --no-trunc {image id}.

You are free to map volumes to any existing or non existing paths inside the container. You will notice when you managed to render the container non functional :slight_smile: