It's possible to list the running docker containers with docker ps, but how can I list the images used by them?
- I'm not sure you differentiate "container" from "image". What do you mean "running images"? A Docker image itself cannot run, but you can create a container using an image. Do you want to list all images currently used by containers?Pierre B.– Pierre B.2022-10-30 09:35:24 +00:00Commented Oct 30, 2022 at 9:35
- Yes, I want to list all the images used in the running Docker containers. I already knew the answer, but since it took me some time to figure it out, I wanted to share the solution using the "Answer your own question" feature of SO.Cl00e9ment– Cl00e9ment2022-10-30 09:39:24 +00:00Commented Oct 30, 2022 at 9:39
- Ah indeed you answered your own question. Maybe clarifying what you mean by "listing running Docker images" by "listing images used by running containers" may help avoid confusionPierre B.– Pierre B.2022-10-30 10:24:58 +00:00Commented Oct 30, 2022 at 10:24
- You're right, I modified it.Cl00e9ment– Cl00e9ment2022-10-30 10:35:29 +00:00Commented Oct 30, 2022 at 10:35
Add a comment |
1 Answer
Listing running Docker images with their tag (registry/namespace/name:tag)
docker inspect --format '{{.Config.Image}}' $(docker ps --format='{{.ID}}') - List the IDs of the running containers with
docker ps --format='{{.ID}}' - List the images associated with the containers with
docker inspect --format '{{.Config.Image}}' <containers_ids>
Listing running Docker images with their digest (registry/namespace/name@digest)
docker image inspect --format '{{index .RepoDigests 0}}' $(docker inspect --format '{{.Image}}' $(docker ps --format='{{.ID}}')) - List the IDs of the running containers with
docker ps --format='{{.ID}}' - List the images IDs associated with the containers with
docker inspect --format '{{.Image}}' <containers_ids> - List the images associated with the images IDs with
docker image inspect --format '{{index .RepoDigests 0}}' <images_ids>