Docker is a platform, based on open source, that automatizes the process of deploying, scaling, and managing applications by utilizing containerization. Through Docker containers, developers can bundle applications and their dependencies into a single unit that can be executed on any Docker-supported platform. When working with Docker containers, it's valuable to have information about actively starting containers and ports they utilize. The command "docker ps" is employed for this specific purpose. Let's delve deeper into this command.
Discover command syntax:
docker ps [OPTIONS]
Options:
- **-a, --all**: List all containers, including stopped ones;
- **-f, --filter**: Filter output using conditions;
- **-n, --last N**: Show only the N most recently created containers;
- **-q, --quiet**: Print container IDs only;
- **-s, --size**: Print container sizes (including all mounted volumes);
- **--format**: Set output format;
- **--no-trunc**: Do not truncate output (show all information).
Examples of usage
Display a list of all the currently active containers:
docker ps
Retrieve a comprehensive list of all containers, including both those that are currently running and those that have been stopped:
docker ps -a
Print container IDs:
docker ps -q
Show details about the most recently created 5 containers:
docker ps -n 5
Display information about containers with certain filters. For example, named "webapp":
docker ps -f name=webapp
Show the sizes of the containers:
docker ps -s
Output information about containers in a specific format. To illustrate, to only showcase the identifiers and names of the containers:
docker ps --format "{{.ID}} {{.Names}}"
Thus, the "docker ps" command is a powerful tool for displaying information about Docker containers. By utilizing this feature, you can obtain a comprehensive summary of the existing container status and effortlessly sort the output by diverse parameters.