This post will cover topic related to ‘Listing Docker Containers’ with multiple docker command examples and different scenerios. So this will help you to understand the command docker and options available in it. Also this post will explain you how to use docker command.
Docker is a powerful tool for containerization that allows developers to package applications and their dependencies into lightweight containers. The docker ps
command is used for listing Docker containers currently running on your system.
Here are several examples of how you can use docker ps
to manage and inspect Docker containers:
Example 1: List all running containers.
docker ps
Output: Displays a table with details of all active containers including their IDs, names, status, and ports.
Example 2: List all containers (including stopped ones).
docker ps -a
Output: Shows a list of all containers, both running and stopped, with detailed information.
Example 3: Display only container IDs.
docker ps -q
Output: Prints only the numeric IDs of the active containers, which is useful for scripting or automation tasks.
Example 4: Display the latest created containers.
docker ps -l
Output: Shows information about the last container created, whether it’s running or stopped.
Example 5: List containers by most recent first.
docker ps -n 5
Output: Limits the output to the last 5 containers created, useful for viewing recent activity.
Example 6: Display only container IDs of the last 3 created containers.
docker ps -n 3 -q
Output: Lists only the IDs of the last 3 containers created, suitable for quick identification.
Example 7: Display containers in reverse order.
docker ps -q -s
Output: Shows container IDs in reverse order of their creation time, displaying the sizes as well.
Example 8: Display total file sizes.
docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}"
Output: Customizes the output format to display specific container details like ID, image, status, and ports in a table format.
Example 9: Display containers by specifying a custom format.
docker ps --format "{{.ID}}: {{.Command}} ({{.Status}})"
Output: Formats the output to show container IDs, commands, and statuses in a user-defined format.
Example 10: Display containers with a specific name pattern.
docker ps --filter "name=mycontainer"
Output: Filters and displays containers whose names match the specified pattern, useful for targeted searches.
To verify whether the docker ps
command executed successfully, you can check the terminal output for the list of containers. If the command was executed without errors, it will display a table or list of containers along with their details. This confirms that Docker was able to retrieve and display the container information as requested.
Also check similar articles.
Executing Commands Inside Docker Containers
How to Create and Run Docker Containers from an Image
How to Manage Kubernetes Plugins
How to Manage Kubernetes Networks
How to Manage Kubernetes Image Manifests
Discussion about this post