Contents

docker ps Command: -a, --filter and --format Examples

By · Updated November 4, 2026

docker ps lists running containers; add -a to include stopped ones. The commands you need most often:

docker ps                                   # running containers
docker ps -a                                # all containers, including stopped
docker ps --filter 'name=^web$'             # only the container named exactly "web"
docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Ports}}"   # pick the columns
docker ps -q                                # IDs only, for use in other commands

Every one of these is run with real output below. For the complete set of container operations, see Container lifecycle.

Syntax

docker ps [OPTIONS]

docker ps and docker container ls are the same command.

Options

OptionDescription
-a, --allList all containers, including stopped ones (by default, only running containers are listed)
-q, --quietOutput only container IDs
-f, --filter FILTERFilter containers; you can use this more than once
--format TEMPLATECustomize the output format with table, json, or a Go template
-n, --last NUMBERShow the n most recently created containers (in any state)
-l, --latestShow the most recently created container
-s, --sizeShow container sizes
--no-truncDo not truncate output (show full IDs and commands)

Common --filter conditions:

ConditionExample
statusstatus=running, status=exited, status=created
namename=web (partial match)
labellabel=team=backend
ancestorancestor=nginx:1.30-alpine (created from a particular image)
exitedexited=137 (by exit code)
publishpublish=8080 (using a particular port)
network / volumenetwork=appnet, volume=pgdata
healthhealth=unhealthy

Name filters use partial matches. For example, name=web also matches web-old. To match exactly, use regular expression anchors: name=^web$. See “Common filter patterns” below for other common conditions and ways to combine them.

Examples

The environment has three containers: the running web (nginx) and worker1 (labeled team=backend), and the stopped stopped1.

Running and all containers

$ docker ps
CONTAINER ID   IMAGE               COMMAND                  CREATED         STATUS         PORTS     NAMES
c260b28b0630   alpine:3.23         "sleep 600"              2 seconds ago   Up 2 seconds             worker1
1ec4fdc5c592   nginx:1.30-alpine   "/docker-entrypoint.…"   8 seconds ago   Up 2 seconds   80/tcp    web

$ docker ps -a
CONTAINER ID   IMAGE               COMMAND                  CREATED         STATUS                     PORTS     NAMES
c260b28b0630   alpine:3.23         "sleep 600"              2 seconds ago   Up 2 seconds                         worker1
17b5b9a8c9ce   alpine:3.23         "true"                   3 seconds ago   Exited (0) 2 seconds ago             stopped1
1ec4fdc5c592   nginx:1.30-alpine   "/docker-entrypoint.…"   8 seconds ago   Up 2 seconds               80/tcp    web

$ docker ps -q
c260b28b0630
1ec4fdc5c592

docker ps does not list stopped1; you can see it with docker ps -a, and its status is Exited (0). -q outputs only IDs, which makes them easy to pass to other commands.

Filtering

$ docker ps -a --filter status=exited
CONTAINER ID   IMAGE         COMMAND   CREATED         STATUS                     PORTS     NAMES
17b5b9a8c9ce   alpine:3.23   "true"    3 seconds ago   Exited (0) 2 seconds ago             stopped1

$ docker ps --filter name=work
CONTAINER ID   IMAGE         COMMAND       CREATED         STATUS         PORTS     NAMES
c260b28b0630   alpine:3.23   "sleep 600"   2 seconds ago   Up 2 seconds             worker1

$ docker ps --filter label=team=backend
CONTAINER ID   IMAGE         COMMAND       CREATED         STATUS         PORTS     NAMES
c260b28b0630   alpine:3.23   "sleep 600"   2 seconds ago   Up 2 seconds             worker1

Custom fields

$ docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
NAMES     IMAGE               STATUS
worker1   alpine:3.23         Up 2 seconds
web       nginx:1.30-alpine   Up 3 seconds

table adds a header row, and \t (Tab) separates the fields. Common fields include .ID, .Names, .Image, .Status, .Ports, .CreatedAt, .Labels, and .Size. Use --format json to output JSON.

Overview of --format fields

The following fields are available for Go template formatting. Use .Label "key" to read the value of a specific label.

FieldExample
.ID064db5f8a5d6
.Namesworker
.Imagealpine:3.23
.Command"sleep 600"
.RunningFor3 seconds ago
.StatusUp 2 seconds
.Staterunning
.Ports0.0.0.0:8080->80/tcp, [::]:8080->80/tcp
.Networksbridge
.Mountsdata
.Labelsmaintainer=NGINX Docker Maintainers <docker-maint@nginx.com>,team=frontend
.Label "key".Label "team" → frontend
.Size8.19kB (virtual 9.11MB)
$ docker ps --format 'table {{.Names}}\t{{.Image}}\t{{.Ports}}'
NAMES     IMAGE               PORTS
worker    alpine:3.23         
cache     redis:8-alpine      6379/tcp
web-old   nginx:1.30-alpine   80/tcp
web       nginx:1.30-alpine   0.0.0.0:8080->80/tcp, [::]:8080->80/tcp

$ docker ps -a --format 'table {{.Names}}\t{{.Status}}\t{{.State}}'
NAMES     STATUS                     STATE
worker    Up 2 seconds               running
job       Exited (3) 2 seconds ago   exited
cache     Up 4 seconds               running
web-old   Up 4 seconds               running
web       Up 5 seconds               running
  • .Names, .Image, and .Ports can be displayed side by side. The PORTS field is blank when no ports are published.
  • .Status is a human-readable status message, while .State is a status value such as running or exited.
$ docker ps --format 'table {{.ID}}\t{{.Command}}\t{{.RunningFor}}'
CONTAINER ID   COMMAND                  CREATED
064db5f8a5d6   "sleep 600"              3 seconds ago
8139aeac8e86   "docker-entrypoint.s…"   5 seconds ago
1b1b15e1e240   "/docker-entrypoint.…"   5 seconds ago
d081d0877260   "/docker-entrypoint.…"   6 seconds ago

$ docker ps --no-trunc --format '{{.Names}}: {{.Command}}'
worker: "sleep 600"
cache: "docker-entrypoint.sh redis-server"
web-old: "/docker-entrypoint.sh nginx -g 'daemon off;'"
web: "/docker-entrypoint.sh nginx -g 'daemon off;'"
  • The table uses the traditional column names (CONTAINER ID, CREATED), which correspond to .ID and .RunningFor.
  • Commands are truncated by default. Use --no-trunc to see the full .Command.
$ docker ps --format 'table {{.Names}}\t{{.Networks}}\t{{.Mounts}}'
NAMES     NETWORKS   MOUNTS
worker    bridge     data
cache     appnet     
web-old   bridge     
web       bridge     

$ docker ps --format '{{.Names}} {{.Labels}}'
worker 
cache 
web-old maintainer=NGINX Docker Maintainers <docker-maint@nginx.com>,team=frontend
web maintainer=NGINX Docker Maintainers <docker-maint@nginx.com>,team=frontend

$ docker ps --format '{{.Names}} team={{.Label "team"}}'
worker team=
cache team=
web-old team=frontend
web team=frontend
  • .Networks and .Mounts list the networks and mounts connected to each container. The field is blank when there are no mounts.
  • .Labels displays all labels, while .Label "team" returns only the value of team. The result is blank if that label is not set.
$ docker ps -s --format 'table {{.Names}}\t{{.Size}}'
NAMES     SIZE
worker    8.19kB (virtual 9.11MB)
cache     4.1kB (virtual 121MB)
web-old   81.9kB (virtual 66.7MB)
web       81.9kB (virtual 66.7MB)
  • .Size with -s displays the writable layer size and the virtual size including the image.

Common filter patterns

$ docker ps --filter name=web --format '{{.Names}}'
web-old
web

$ docker ps --filter 'name=^web$' --format '{{.Names}}'
web

$ docker ps --filter network=appnet --format '{{.Names}}'
cache

$ docker ps --filter label=team=frontend --format '{{.Names}}'
web-old
web
  • name=web performs a partial match, so web-old also appears. name=^web$ matches only containers whose name is exactly web.
  • network and label filter by network name and label, respectively.
$ docker ps -a --filter exited=3 --format '{{.Names}} {{.Status}}'
job Exited (3) 4 seconds ago

$ docker ps -a --filter status=exited --format '{{.Names}}'
job

$ docker ps --filter publish=8080 --format '{{.Names}} {{.Ports}}'
web 0.0.0.0:8080->80/tcp, [::]:8080->80/tcp

$ docker ps --filter volume=data --format '{{.Names}}'
worker

$ docker ps --filter ancestor=nginx:1.30-alpine --format '{{.Names}}'
web-old
web
  • exited=3 filters by exit code; status=exited lists all containers that have exited.
  • publish, volume, and ancestor filter by published port, mounted volume, and the image used to create the container, respectively.
$ docker ps --filter name=web --filter status=running --format '{{.Names}}'
web-old
web
  • When you use --filter more than once, all conditions must match (AND). Here, the name must match web and the status must be running.

Counting and hostnames

$ docker ps -a --format '{{.Names}}' | wc -l
5

$ docker ps -q | wc -l
4
  • wc -l counts the output lines. -a includes the stopped job, giving a total of 5; the default lists only running containers, giving a total of 4.
  • -q outputs only container IDs, with one container per line, so you can count them directly.

docker ps has no .Hostname field; referencing it directly results in an error. Also, do not pass a container name as a positional argument to docker ps: for example, docker ps --format json web fails. Use --filter name= instead.

$ docker ps --format json web
docker: 'docker ps' accepts no arguments

Usage:  docker ps [OPTIONS]

Run 'docker ps --help' for more information

$ docker ps --format '{{.Names}} {{.Hostname}}'
failed to execute template: template: :1:13: executing "" at <.Hostname>: can't evaluate field Hostname in type *formatter.ContainerContext
  • docker ps does not accept a container name as a positional argument. To select containers, use --filter name=name.
  • .Hostname is not among the fields available to docker ps --format, so the template returns a field error when it runs.

To look up a hostname, use .Config.Hostname with docker inspect. You can also look up each name listed by docker ps one at a time:

$ docker inspect -f '{{.Config.Hostname}}' cache
cache-host

$ docker ps --format '{{.Names}}' | while read n; do echo "$n $(docker inspect -f '{{.Config.Hostname}}' $n)"; done
worker 064db5f8a5d6
cache cache-host
web-old 1b1b15e1e240
web d081d0877260
  • For a single lookup, pass the container name directly to docker inspect.
  • The loop looks up each name in turn. Containers without a custom hostname use the container ID as their hostname.

Container size and most recently created containers

$ docker ps -s
CONTAINER ID   IMAGE               COMMAND                  CREATED         STATUS         PORTS     NAMES     SIZE
c260b28b0630   alpine:3.23         "sleep 600"              3 seconds ago   Up 2 seconds             worker1   4.1kB (virtual 9.1MB)
1ec4fdc5c592   nginx:1.30-alpine   "/docker-entrypoint.…"   9 seconds ago   Up 3 seconds   80/tcp    web       86kB (virtual 66.8MB)

$ docker ps -n 1
CONTAINER ID   IMAGE         COMMAND       CREATED         STATUS         PORTS     NAMES
c260b28b0630   alpine:3.23   "sleep 600"   3 seconds ago   Up 2 seconds             worker1
  • The first number in SIZE is the amount of data written by the container itself (the writable layer). virtual includes the image. The nginx container wrote some temporary files at startup, so it is 86kB.
  • -n 1 displays only the one most recently created container.

Batch operation: remove all stopped containers

$ docker rm $(docker ps -aq --filter status=exited)
17b5b9a8c9ce

$(...) runs the command inside first, then uses the result (the IDs of all stopped containers) as arguments to docker rm. You can get the same result with docker container prune (see Freeing up disk space).

PowerShell also supports the $(...) syntax. Windows CMD does not, so use docker container prune instead.

Exercises

Exercise: List all containers created from nginx:1.30-alpine, including stopped ones, and show only their names and statuses.

Answer
docker ps -a --filter ancestor=nginx:1.30-alpine --format "table {{.Names}}\t{{.Status}}"

FAQ

Why can't I see a container I just ran with docker ps?

docker ps lists only **running** containers. If a container has stopped (for example, a one-off command finished or startup failed), use docker ps -a.

Are docker ps and docker container ls the same?

Yes. docker ps, docker container ls, docker container list, and docker container ps are all the same command.

What's the difference between Exited (0) and Exited (1) in STATUS?

The number in parentheses is the exit code. 0 means the program exited successfully; a nonzero value means an error occurred. 137 means it was forcefully terminated (for example, due to insufficient memory). Use docker logs to find out why.

How can I show only containers with a certain name using docker ps?

Use docker ps --filter name=name. Name filters use partial matches. To match a name exactly, such as showing only web, use --filter 'name=^web$'.

How can I show a container's hostname with docker ps?

The docker ps format has no .Hostname field. Query it with docker inspect -f '{{.Config.Hostname}}' container-name. To query multiple containers, run docker inspect for each name.

Updated November 4, 2026