docker ps - show image ID instead of name
Asked Answered
A

3

20

I display running containers using docker ps command. There is an IMAGE column that shows name of the image that each container was created from. However in the meantime (while containers were running) I have rebuilt some images. The new images have the same names but different IDs. Now I'd like to check from which image specific container was run. I cannot deduce this information using only image name. I need image ID. Is there any possibility to display ID of the image that was used to run specific container?

Automata answered 7/1, 2019 at 13:35 Comment(0)
B
37

You can pass multiple container-ids to the docker inspect command and then use the --format to only get the values that you want.

docker inspect --format='{{.Id}} {{.Name}} {{.Image}}' $(docker ps -aq)

This will give you a list of the docker container Ids, names and image IDs that are being used for all of your containers.

asdf1234 /mydockercontainer sha256:abcd1234

https://docs.docker.com/engine/reference/commandline/inspect/

Beuthen answered 7/1, 2019 at 14:3 Comment(2)
What if instead of image id, I want the name of the image being used by the containers?Inkberry
Try this docker inspect --format="{{.Config.Image}}" CONTAINER_NAMEIntensity
A
7

I found that docker inspect <container-id> can be used for this purpose. It displays an image field containing full hash.

Automata answered 7/1, 2019 at 13:44 Comment(1)
docker inspect <container-id> | grep Image | grep sha256Daphie
V
-8
docker images

will show you the image names and their IDs

Vacuity answered 7/1, 2019 at 13:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.