LinuxCommandLibrary

docker-ps

List running Docker containers

TLDR

List currently running Docker containers

$ docker ps
copy

List all Docker containers (running and stopped)
$ docker ps [[-a|--all]]
copy

Show the latest created container (includes all states)
$ docker ps [[-l|--latest]]
copy

Filter containers that contain a substring in their name
$ docker ps [[-f|--filter]] "name=[name]"
copy

Filter containers that share a given image as an ancestor
$ docker ps [[-f|--filter]] "ancestor=[image]:[tag]"
copy

Filter containers by exit status code
$ docker ps [[-a|--all]] [[-f|--filter]] "exited=[code]"
copy

Filter containers by status (created, running, removing, paused, exited and dead)
$ docker ps [[-f|--filter]] "status=[status]"
copy

Filter containers that mount a specific volume or have a volume mounted in a specific path
$ docker ps [[-f|--filter]] "volume=[path/to/directory]" --format "table [.ID]\t[.Image]\t[.Names]\t[.Mounts]"
copy

SYNOPSIS

docker ps [OPTIONS]
Note: The command 'docker-ps' is not a standard Docker command; this analysis pertains to 'docker ps'.

PARAMETERS

-a, --all
    Show all containers, including those that are stopped or exited. By default, only running containers are shown.

-f, --filter FILTER
    Filter output based on conditions provided, such as status=exited, ancestor=ubuntu, or name=my-container.

--format string
    Pretty-print containers using a Go template, allowing custom output formats. For example, --format '{{.ID}}: {{.Names}}'.

-n, --last int
    Show n last created containers (includes all states: running, exited, etc.). The default is -1, meaning all containers when combined with -a.

--no-trunc
    Don't truncate output, showing full container IDs and names instead of shortened versions.

-q, --quiet
    Only display numeric IDs of containers, useful for scripting or piping output to other commands.

-s, --size
    Display total file sizes of the container and its writable layer.

DESCRIPTION

docker ps is a fundamental command within the Docker command-line interface (CLI) used to inspect and manage Docker containers. It provides a quick overview of containers that are currently running on your system, showing crucial details such as their ID, the image they are based on, the command executed inside them, when they were created, their current status (e.g., Up, Exited), ports they expose, and their names. By default, docker ps only displays active, running containers. However, with various options, it can be extended to show all containers, including those that have stopped or exited, filter results based on specific criteria, or format the output for easier parsing. This command is indispensable for developers and system administrators working with Docker, enabling them to quickly verify container health, identify running services, and prepare for further container management actions like stopping, starting, or removing containers.

CAVEATS

  • By default, docker ps only lists running containers. Users often forget the -a or --all option when troubleshooting missing containers that are stopped.
  • The output can be quite wide, requiring a larger terminal window or the use of --no-trunc to see full details.
  • Filtering with --filter requires understanding of available filter keys (e.g., status, name, id, label) and their valid values.

UNDERSTANDING OUTPUT COLUMNS

A typical docker ps output includes:
CONTAINER ID: A unique identifier for the container.
IMAGE: The Docker image used to create the container.
COMMAND: The command executed when the container starts.
CREATED: How long ago the container was created.
STATUS: The current state of the container (e.g., Up X minutes, Exited Y seconds ago).
PORTS: Port mappings between the host and the container.
NAMES: The name assigned to the container (either automatically generated or user-defined).

HISTORY

The docker ps command has been a core component of the Docker CLI since the early days of Docker's development, which began around 2013. As Docker revolutionized containerization, docker ps quickly became one of the most frequently used commands, essential for monitoring and managing the lifecycle of containers. Its syntax and core functionality have remained largely consistent, reflecting its fundamental role in providing immediate visibility into the state of containers running on a Docker host. Continuous development has focused on adding useful options like advanced filtering and formatting capabilities, enhancing its utility for more complex container orchestration scenarios.

SEE ALSO

docker run(1), docker stop(1), docker start(1), docker rm(1), docker images(1), docker logs(1), ps(1)

Copied to clipboard