Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Docker ps Command

Docker ps Command

Docker Command ReferenceDocker Command Reference


The docker ps command is used to list Docker containers.

By default, the docker ps command only shows running containers, but you can specify options to show all containers, including stopped ones.

Syntax

docker ps [OPTIONS]

OPTIONS description:

Example

1. List information of all running containers

By default, docker ps only shows running containers.

docker ps

CONTAINER ID   IMAGE          COMMAND                ...  PORTS                    NAMES

09b93464c2f7   nginx:latest   "nginx -g 'daemon off" ...  80/tcp, 443/tcp          myrunoob

96f7f14e99ab   mysql:5.6      "docker-entrypoint.sh" ...  0.0.0.0:3306->3306/tcp   mymysql

Output details:

CONTAINER ID: Container ID.

IMAGE: The image used.

COMMAND: The command run when the container was started.

CREATED: The container's creation time.

STATUS: Container status.

There are 7 statuses:

PORTS: The container's port information and the connection type used (tcp/udp)

NAMES: The automatically assigned container name.

2. List all containers, including stopped ones



docker ps -a

Show all containers, including stopped ones.

3. Show only container IDs



docker ps -q

Show only container IDs.

** 4. Display the most recently created container**



docker ps -l

Display the most recently created container, including all states.

** 5. Display the n most recently created containers**



docker ps -n 3

Display the 3 most recently created containers, including all states.

6. Show container sizes

docker ps -s

Show the size of containers.

** 7. Filter displayed containers by conditions**



docker ps -f "status=exited"

Show containers whose status is exited.



docker ps -f "name=my_container"

Show containers whose names contain my_container.

** 8. Format the output**



docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}"

Display container IDs, names, and statuses in tabular form.

Common filters

Use Cases


Docker Command ReferenceDocker Command Reference