-
Notes
Please see these pages for more information:
https://docs.docker.com/engine/reference/commandline/ps/
https://docs.docker.com/engine/reference/commandline/container_ls/
For the following sections we will use the nginx and ubuntu images as examples to show how to use docker commands to list containers.
Let's run the nginx image:
Let's run the ubuntu image:
-
docker ps
The 'docker ps' command has the following syntax:
The 'docker ps' command has the following options:
Let's verify that nginx is up and running:
Note that the ubuntu container doesn't appear when listing the running containers.
The ubuntu container was started and exited immediately, because it doesn't have a process that run in the foreground.
-
docker ps -a ('--all')
The 'docker ps' command lists only running containers.
To list all containers including stopped (or paused, failed, ...), use the option '-a' ('--all'):
-
docker ps -s ('--size')
To print the size of the container, use the option '-s' ('--size'):
-
docker ps --no-trunc
To print the full container ID and the whole command, use the option '--no-trunc':
-
docker ps -q ('--quiet')
To print only the container ID, use the option '-q' ('--quiet'):
The option '-q' can be useful for example in case you want to write scripts to do some actions on the containers.
For example, if you want to stop all running container:
To remove all containers:
-
docker ps --format
To print the format the output of the command, use the option '--format'.
You can use either json or GO template to format the output.
First let's find out the available data that we can format (the trick is to print the output of the 'docker ps' command as json):
To print only the container ID and the image name:
To print the container ID and the image name in a table format:
-
docker ps -f ('--filter')
To filter the output based on some conditions, use the option '-f' ('--filter'):
-
docker container ls
The 'docker container ls' command has the following syntax:
The 'docker container ls' command has the following options:
Let's verify that nginx is up and running:
For details how to to use 'docker container ls' options, please see "docker ps" options usage above.