LinuxCommandLibrary

docker-containers

List Docker containers

TLDR

List currently running Docker containers

$ docker container ls
copy

Start one or more stopped containers

$ docker container start [container1_name] [container2_name]
copy

Kill one or more running containers

$ docker container kill [container_name]
copy

Stop one or more running containers

$ docker container stop [container_name]
copy

Pause all processes within one or more containers

$ docker container pause [container_name]
copy

Display detailed information on one or more containers

$ docker container inspect [container_name]
copy

Export a container's filesystem as a tar archive

$ docker container export [container_name]
copy

Create a new image from a container's changes

$ docker container commit [container_name]
copy

SYNOPSIS

docker containers [OPTIONS]

PARAMETERS

-a, --all
    Show all containers (default shows just running)

-f, --filter filter
    Filter output based on conditions provided

--format string
    Format the output using the given Go template

-n, --last int
    Show n last created containers (includes all states)

-l, --latest
    Show the latest created container (includes all states)

-q, --quiet
    Only display container IDs

-s, --size
    Display total file sizes

DESCRIPTION

The `docker containers` command (often used implicitly via `docker ps`) provides a way to view the active Docker containers on a system. It lists information about each container, such as its ID, name, status (running, exited, etc.), ports, and the command that's being executed within it. This command is essential for monitoring, managing, and debugging Dockerized applications. The output can be filtered and formatted using various options. While `docker containers` itself is not a standalone command (it's a subcommand of `docker`), it's the core functionality that users access when they want a quick overview of their running containers.

CAVEATS

The `docker containers` command is often used implicitly through the `docker ps` command, which is an alias to it. The format and available filters can change slightly between Docker versions.

FILTERING

The `-f` or `--filter` option is very powerful.
You can filter based on container name, id, status (created, restarting, running, removing, paused, exited, dead), labels and more.
For example: docker ps -f "status=running"

FORMATTING OUTPUT

The `--format` option is used to customize the output using Go templates. This allows for precise control over which container properties are displayed and how they are formatted.
For Example: docker ps --format "{{.ID}}: {{.Names}}"

IMPLICIT USAGE

The `docker containers` command is rarely used directly. The command `docker ps` is an alias and preferred by most users.

HISTORY

The `docker containers` command and its alias `docker ps` have been part of Docker since its early releases. They evolved along with Docker's growing feature set, incorporating new options for filtering and output formatting to handle more complex container management scenarios.

Originally, it provided a simple list of running containers. Over time, more advanced features were added to improve manageability.

SEE ALSO

docker ps(1), docker run(1), docker stop(1), docker rm(1), docker inspect(1)

Copied to clipboard