3

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.

1
  • Are you using Docker SDK from python? Commented Apr 5, 2019 at 20:15

3 Answers 3

9

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.

Sign up to request clarification or add additional context in comments.

4 Comments

aaha ... thanks. That gives me docker image under RepoTags, why it is an array ?
You can apply multiple tags to the same image, they'll be listed there.
so which one would give me the image repotag or repodigests? If there are multiple repotags how would I know which is the base image?
Not sure what you're asking; by base image do you mean the one from which your 8d6721e9 image was built?
0

ok I jsut checked docker image inspect also works with the sha.. hash so I asume the sdk ( which probably just passes it along to cmd ) should also be able to handle it like in this example

>>> client.containers.list()
[<Container '45e6d2de7c54'>, <Container 'db18e4f20eaa'>, ...]

>>> container = client.containers.get('45e6d2de7c54')

>>> container.attrs['Config']['Image']
"bfirsh/reticulate-splines"

>>> container.logs()
"Reticulating spline 1...\n"

>>> container.stop()

Comments

0

I use Config.Image it's a field of the container's inspect output plus jq to parse the JSON output :

docker inspect <container-id/name> | jq -r '.[0].Config.Image'

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.