Search notes:

docker ps

docker ps lists containers.
docker ps [options]

Options

-a --all Show all containers. Without --all, only running containers are shown.
-f --filter filter Filter output based on conditions provided
--format string Pretty-print containers using a Go template
-n --last n Show n last created containers, regardless of their state. The default for n is -1
-l --latest Show the latest created container, regardless of its state
--no-trunc Don't truncate output
-q --quiet Only display container IDs
-s --size Display total file sizes

Display running containers

docker ps lists running containers.
In this example, no container is running, so an empty list is returned:
C:\> docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
Start a new container:
C:\> docker run -it mcr.microsoft.com/windows/nanoserver:1809 cmd.exe
C:\>
This (running) new container can now be seen with docker ps in another console or terminal (or cmd.exe or PowerShell on Windows):
C:\> docker ps
CONTAINER ID        IMAGE                                       COMMAND             CREATED             STATUS              PORTS               NAMES
8b0d27e6dd49        mcr.microsoft.com/windows/nanoserver:1809   "cmd.exe"           5 minutes ago       Up 5 minutes                            infallible_haslett

Display all containers

In order to see all containers, running and previously running, docker ps -a can be used:
C:\> docker ps -a
CONTAINER ID        IMAGE                                       COMMAND                   CREATED             STATUS                         PORTS               NAMES
8b0d27e6dd49        mcr.microsoft.com/windows/nanoserver:1809   "cmd.exe"                 7 minutes ago       Up 7 minutes                                       infallible_haslett
04f949ba4462        mcr.microsoft.com/windows/nanoserver:1809   "cmd.exe"                 23 minutes ago      Exited (9009) 21 minutes ago                       musing_haibt
5811d62cf83f        mcr.microsoft.com/windows/nanoserver:1809   "cmd.exe"                 20 hours ago        Exited (0) 20 hours ago                            thirsty_turing
299444befdee        hello-world                                 "cmd /C 'type C:\\hel…"   20 hours ago        Exited (0) 20 hours ago                            adoring_babbage
f33e6b639326        hello-world                                 "cmd /C 'type C:\\hel…"   21 hours ago        Exited (0) 21 hours ago                            upbeat_bartik
ada3b521615d        hello-world                                 "cmd /C 'type C:\\hel…"   21 hours ago        Exited (0) 21 hours ago                            nifty_cray

Print the entire command

Long commands are truncted by docker ps:
$ docker ps
CONTAINER ID   IMAGE                                         COMMAND                  CREATED         STATUS                   PORTS                    NAMES
43bd9c883cf8   container-registry.oracle.com/database/free   "/bin/sh -c 'exec $O…"   4 minutes ago   Up 4 minutes (healthy)   0.0.0.0:1521->1521/tcp   ora23c
The following variation prints the entire command:
$ docker ps --no-trunc --format "{{.Command}}"
"/bin/sh -c 'exec $ORACLE_BASE/$RUN_FILE'"

Filtering containers

The result set of docker ps can be filtered with docker ps … -filter "key=value":
C:\> docker ps -a --filter "exited=9009"
CONTAINER ID        IMAGE                                       COMMAND             CREATED             STATUS                         PORTS               NAMES
04f949ba4462        mcr.microsoft.com/windows/nanoserver:1809   "cmd.exe"           26 minutes ago      Exited (9009) 24 minutes ago                       musing_haibt
Possible key names are
id The id of a container
name The name of a container
label ?
exited the exit code of a container, useful only with -a
status created, restarting, running, removing, paused, exited or dead
ancestor <image-name>, <image-name>:<tag>, <image-id> or <image@digest>.
before / since finds containers that were created before or after a container that is identified by its id or name
volume
network
publish / expose
health starting, healthy, unhealthy or none
isolation Only on Windows: one of default, process or hyperv
is-task true or false

Format result

The --format argument specifies a Go template which controls which columns are listed in the output of docker ps:
docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'

See also

Docker commands
docker ps gets its command name ps from shell command with the same name.

Index