Docker ps Command

Docker ps Command

docker ps : list containers

Docker ps Syntax

docker ps [OPTIONS]

OPTIONS Description:

  • -a : Show all containers, including non-running ones.
  • -f : Filter what is displayed based on conditions.
  • –format : Specify the template file for the returned value.
  • -l : Show recently created containers.
  • -n : List the n most recently created containers.
  • –no-trunc : Do not truncate the output.
  • -q : Silent mode, show only container number.
  • -s : Show the total file size.

Docker ps Examples

Lists information about all running containers.

apidemos@apidemos:~$ docker ps
CONTAINER ID   IMAGE          COMMAND                ...  PORTS                    NAMES
09b93464c2f7   nginx:latest   "nginx -g 'daemon off" ...  80/tcp, 443/tcp          myapidemos
96f7f14e99ab   mysql:5.6      "docker-entrypoint.sh" ...  0.0.0.0:3306->3306/tcp   mymysql

Output details are presented.

CONTAINER ID: The container ID.

IMAGE: The image to use.

COMMAND: The command to run when starting the container.

CREATED: The creation time of the container.

STATUS: The status of the container.

There are 7 types of status.

  • created
  • restarting
  • running
  • removing
  • paused
  • exited
  • dead

PORTS: Port information of the container and the type of connection used (tcp\udp).

NAMES: The name of the automatically assigned container.

Lists information about the last 5 containers created.

apidemos@apidemos:~$ docker ps -n 5
CONTAINER ID        IMAGE               COMMAND                   CREATED           
09b93464c2f7        nginx:latest        "nginx -g 'daemon off"    2 days ago   ...     
b8573233d675        nginx:latest        "/bin/bash"               2 days ago   ...     
b1a0703e41e7        nginx:latest        "nginx -g 'daemon off"    2 days ago   ...    
f46fb1dec520        5c6e1090e771        "/bin/sh -c 'set -x \t"   2 days ago   ...   
a63b4a5597de        860c279d2fec        "bash"                    2 days ago   ...

List all created container IDs.

apidemos@apidemos:~$ docker ps -a -q
09b93464c2f7
b8573233d675
b1a0703e41e7
f46fb1dec520
a63b4a5597de
6a4aa42e947b
de7bb36e7968
43a432b73776
664a8ab1a585
ba52eb632bbd
...
Like(0)