pythondockercontainers

How to find docker image for a container?


I am trying to find the corresponding docker image for a container.

docker inspect <container-id> 

This gives a whole lot of information. It also gives the docker image if I do : docker inspect ['Config']['Image']

But this is not the reliable source as some times it just gives some SHA, something like sha256:00954e990edd7c78dff64c8031c58c07cb36b4591dca3923b5a1a1c31199e54c

Is there a reliable way to find the docker image for a container?

Especially through Python code.

I have docker client but that doesn't support any query that can give me Image name.


Solution

  • docker inspect <container-id> gives you the Image property, as you've noticed:

    "Image": "sha256:8d6721e9290e96cc34faeee7a525311a400598e7fee170190c73ce103dd621ce"
    

    You can use that hash value to subsequently inspect the image itself: docker inspect <image-id>. In the example above "8d6721e9290e96cc34faeee7a525311a400598e7fee170190c73ce103dd621ce" is the image ID.