🎓 A1Learner
🔍
0 of 50 lessons completed

List Containers and Images

docker ps lists containers, and docker images lists images. Each column answers one question: what is running, from which image, on which port.

List running containers

This command lists running containers with three columns.

docker ps --format "{{.Names}} {{.Image}} {{.Ports}}"

List images

This command lists images with repository, tag and size.

docker images nginx --format "{{.Repository}}:{{.Tag}} {{.Size}}"

Example

docker run -d --name g3-web -p 8081:80 nginx:1.27-alpine >/dev/null
docker ps --format "{{.Names}} {{.Image}} {{.Ports}}"
docker images nginx --format "{{.Repository}}:{{.Tag}} {{.Size}}"

Key points

  • docker ps lists running containers only.
  • docker ps -a lists stopped containers too.
  • docker images lists images on the machine, with tag and size.
  • The NAMES column holds the container name. The IMAGE column holds its image.
  • Use --format to pick the columns you want, in the order you want.

In this example, Docker starts nginx and then lists containers and images. The container row shows the name, the image and the mapped port. The image row shows the repository, the tag and the size. Each column answers one question about the running system.

Note

A container ID is a long random string. Names are the stable way to refer to a container.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

Which command lists stopped containers too?