2

It's possible to list the running docker containers with docker ps, but how can I list the images used by them?

4
  • 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? Commented 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. Commented 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 confusion Commented Oct 30, 2022 at 10:24
  • You're right, I modified it. Commented Oct 30, 2022 at 10:35

1 Answer 1

5

Listing running Docker images with their tag (registry/namespace/name:tag)

docker inspect --format '{{.Config.Image}}' $(docker ps --format='{{.ID}}') 
  1. List the IDs of the running containers with docker ps --format='{{.ID}}'
  2. 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}}')) 
  1. List the IDs of the running containers with docker ps --format='{{.ID}}'
  2. List the images IDs associated with the containers with docker inspect --format '{{.Image}}' <containers_ids>
  3. List the images associated with the images IDs with docker image inspect --format '{{index .RepoDigests 0}}' <images_ids>
Sign up to request clarification or add additional context in comments.

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.