How to List Docker Containers

July 16, 2024

Introduction

Proper Docker container management is one key aspect of a successful multi-container app deployment. Listing containers is a standard management operation that allows users to obtain important information about container health, status, and configuration parameters.

This guide shows you how to list Docker containers.

How to list Docker containers.

Prerequisites

  • Command-line access.
  • Administrative privileges on the system.
  • Docker installed.

How to List Docker Containers

Listing containers available on the system provides a user with the following information about each container:

  • Container ID. A unique alphanumeric string for each container, which helps identify and distinguish between the containers.
  • Image. The template used for the creation of the container.
  • Command. An instruction executed when Docker started the container.
  • Age. The time passed since the container was created.
  • Status. The information on whether the container is running, stopped, or in error.
  • Ports. Any ports forwarded to the container for networking.
  • Name. An identifying string created by the user (for example, with the docker run command) or randomly generated by Docker.

The following sections provide information about two commands, docker ps and docker container ls, that output a container list.

docker ps

The docker ps command (short for docker process status) is the original Docker command for listing containers. Below is the command syntax:

docker ps [options]

When executed without any options, the command outputs a list of running containers:

docker ps
The docker ps command outputting a list of running containers.

The table below lists the options that the command accepts as part of its syntax:

OptionDescription
-a, --allShow all running and stopped containers.
-f, --filter [condition]Filter output based on [condition].
--format [string]Format output based on a template. Possible values of [string] are table, table [go-template], json, and [go-template].
-n, --last [number]Show [number] newest containers (all states).
-l, --latestShow the newest container (all states).
--no-truncDisable output truncation.
-q, --quietShow container IDs only.
-s, --sizeShow total file sizes.
--helpShow help.

docker container ls

The docker container ls is a newer command for container listing intended to replace docker ps in the future and ensure consistency across Docker CLI.

However, as of the Docker version 25.05, docker container ls and docker ps exist side by side as aliases. The commands perform all the same functions, have the same options, and can be used interchangeably.

For example, below is the docker ps command for printing a list of containers with truncation disabled:

docker ps --no-trunc

Another way to write this command is by using docker container ls:

docker container ls --no-trunc

List Docker Containers: Examples

A Docker container list can be customized using various options and combinations of options. The examples below illustrate some of the more common usage scenarios.

List All Containers

To list all containers, both running and stopped, add option –a:

docker ps –a

Refer to the STATUS column to learn about the state of the container.

Docker displaying all the containers currently on the system, regarding of their status.

Add the -q (quiet) option to show the list of container IDs only:

docker ps –aq
Docker displaying container IDs of all the containers on the system.

View File Sizes

The default container list view does not show how much storage each container takes up. To list the total file size of each container, use the option –s (size):

docker ps –s

The SIZE column appears in the output, showing the relevant information.

Docker list with an additional column that shows how much storage each container takes up.

See Most Recently Created Container

When working with many containers, it may be challenging to find the newest ones just by looking at the list. To list the latest created container only, use the option –l (latest):

docker ps –l
Showing the latest created container.

While -l outputs only the newest container on the host, -n prints any number of recent containers. For example, to see the last three containers, type the following:

docker ps -n 3

The list now shows three items.

Showing three newest containers.

Conclusion

After reading this tutorial, you should be able to list containers available on your system and customize the list view according to your needs. The article also provided examples of the most frequent list actions in Docker.

Find other container management commands and much more in our Docker Commands Cheat Sheet.

Was this article helpful?
YesNo
Marko Aleksic
Marko Aleksić is a Technical Writer at phoenixNAP. His innate curiosity regarding all things IT, combined with over a decade long background in writing, teaching and working in IT-related fields, led him to technical writing, where he has an opportunity to employ his skills and make technology less daunting to everyone.
Next you should read
Docker Commands
December 7, 2022

Docker has earned a reputation as one of the most popular open-source platforms for application development...
Read more
How to Install Docker Compose on CentOS 7
November 19, 2019

If you are a Docker user, you are most likely running and managing multiple containers at the same time...
Read more
How to Commit Changes to a Docker Image with Examples
February 14, 2024

Docker allows users to run a container based on an existing image. This feature is both time efficient and...
Read more
How To Remove Docker Images, Containers, Networks & Volumes
February 7, 2019

Docker allows users to create a container in which an application or process can run. In this guide, you will...
Read more