docker compose ps command
The docker compose ps command is used to list containers related to a Docker Compose project and their status.
docker compose ps can display the running status, port mappings, and other information of all service containers in the current project.
Syntax
docker compose ps [OPTIONS] [SERVICE...]
- SERVICE(Optional): Specify the service name to view status. If not specified, the container status of all services will be listed.
OPTIONS:
-a, --all: List all containers, including stopped ones.-q, --quiet: Show only container IDs, without other information.--services: List only service names, without displaying container details.--filter: Filter the output results based on conditions. For example, you can filter containers by status.
Output information
- NameContainer name.
- CommandThe command running in the container.
- State: The status of the container (e.g., Up, Exited).
- Ports: The port mappings of containers.
Example
1. List all running containers
docker compose ps
Display the containers currently running in the current project and their status.
2. List all containers (including stopped containers)
docker compose ps -a
Include stopped containers and list the status of all containers.
3. Display container IDs only
docker compose ps -q
Return only container IDs, without other details.
4. List the names of all services
docker compose ps --services
Show only service names, without listing container details.
5. Filter containers by status
docker compose ps --filter "status=running"
List only containers with status "running".
other extensions