Cl00e9ment
Cl00e9ment

Reputation: 823

How can I list images used by running Docker containers?

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

Upvotes: 1

Views: 2542

Answers (1)

Cl00e9ment
Cl00e9ment

Reputation: 823

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>

Upvotes: 4

Related Questions