You are currently viewing Docker PS Command – Everything You Need to Know

Docker PS Command – Everything You Need to Know

Docker has changed the way developers build, ship, and run applications. Docker containers enable developers to encapsulate applications and their dependencies, ensuring seamless deployment across various environments. One of the fundamental commands in Docker is docker ps, which allows you to manage and monitor your Docker containers. 

This guide, being a part of our Docker consulting services, aims to resolve the complexities, providing both beginners and seasoned developers with a comprehensive understanding of docker ps. Let’s get started with the basics.

What is docker ps?

The docker ps command is a fundamental tool in Docker. When you type docker ps in the command line interface (CLI), it provides you with a list of all the currently running Docker containers on your system. This command specifically shows active containers, making it easy for developers and system administrators to monitor their running applications.

By default, docker ps displays essential information about each container, such as its unique ID, names, status, ports, and resource usage statistics like CPU and memory. This quick overview helps users keep track of their running containers. This makes it simpler to manage and troubleshoot applications in a Docker environment.

In addition to docker ps, there are various options and flags that can be used with the command to filter, format, and sort the output, providing more detailed and customized information about the running containers.

Syntax and Available Options for ‘docker ps’

The structure of the ‘docker ps’ command is straightforward: docker ps [OPTIONS].

By default, ‘docker ps’ shows only running containers. However, its flexibility becomes apparent through the range of options it provides, allowing you to customize the displayed information.

For instance, the -a or –all option exhibits all containers, not just the active ones. The -s or –size option discloses the total file sizes of individual containers. Additionally, the -f or –filter option empowers you to refine the output based on specific criteria.

This array of options illustrates ‘docker ps’ as a versatile tool for managing Docker containers, showcasing its dynamic nature in container management.

Also Check: Our blog post on docker cleanup

What are all the Docker ps command Options?

Here is the list of docker ps command options:

-a, –all: Displays all containers, not just the active ones.
-f, –filter: Filters the list based on specific conditions applied.
–format: Allows manipulation of the output using a GO template, determining how the output appears.
-n, –last: Shows the last created containers, including all states.
-l, –latest: Displays the latest created container, regardless of its current state.
–no-trunc: Presents output without truncating the data, ensuring complete information.
-q, –quiet: Shows only the numeric IDs of the containers, providing a concise output.
-s, –size: Reveals the total file size occupied by the container, offering insights into storage utilization.

How does the Docker ps Command Operate?

To execute the ‘docker ps’ command, the system must have Docker CLI installed. When this command is run, Docker CLI interprets it in JSON format and communicates with the Docker daemon through an API call. The Docker daemon, in return, provides the list of running containers to the standard output, which is the terminal, unless specific options are specified in the command.

‘Docker ps’ and Its Connection to Linux Process Status (ps)

If you’re familiar with Linux, you might recognize a resemblance between ‘docker ps’ and the Linux ‘ps’ command. This resemblance is intentional.

Docker, which relies on Linux containers, frequently reflects Linux commands. In ‘docker ps’, the ‘ps’ signifies ‘process status’, akin to the Linux ‘ps’ command.

However, there’s a difference. While the Linux ‘ps’ command lists all processes on a system, ‘docker ps’ specifically enumerates Docker containers.

Check Out: Our blog post on docker clear cache

The Significance of JSON in Executing the ‘docker ps’ Command

In the execution of the ‘docker ps’ command, JSON (JavaScript Object Notation) is utilized to structure its output. JSON, a lightweight data-interchange format, is designed for easy readability and writing.

When you execute ‘docker ps’, the Docker daemon creates a JSON object containing the information about Docker containers. This JSON object is subsequently interpreted by the Docker CLI, transforming it into the visible output on your terminal.

Examples for better understanding

  1. Display only the containers that are currently running.
All About Docker ps Command

The output will look like:

All About Docker ps Command
  1. Show a list of all containers, regardless of whether they are running or not.
All About Docker ps Command

The output will look like:

  1. Utilize the ‘-f’ or ‘–filter’ option to refine the container list based on specific criteria such as name, ID, or label.
All About Docker ps Command

The output will look like:

All About Docker ps Command
  1. Customize the output of the ‘docker ps’ command using the GO template with the format option.
All About Docker ps Command

The output will look like:

All About Docker ps Command
  1. View the last ‘n’ number of recently created containers in a given situation.
All About Docker ps Command

The output will look like:

All About Docker ps Command
  1. Retrieve information about the latest container created.

The output will look like:

All About Docker ps Command
  1. Prevent truncation of column data due to limited screen size; display containers without data cutoff.
All About Docker ps Command

The output will look like:

All About Docker ps Command
  1. Show only the unique identification (ID) of the containers.
All About Docker ps Command

The output will look like:

All About Docker ps Command
  1. Obtain the size information of containers without relying on the ‘format’ option.
All About Docker ps Command

The output will look like:

All About Docker ps Command

Read More: About got permission denied while trying to connect to the docker daemon socket

Advantages of docker ps command

The docker ps command is a powerful tool in the Docker ecosystem, offering several advantages to developers, system administrators, and anyone working with Docker containers. Here are the key advantages of the docker ps command:

  • Container Visibility: docker ps provides a quick overview of all the running containers on your system. It allows you to see which containers are active, helping you monitor your applications in real-time.
  • Status Check: It shows the status of containers, indicating whether they are running, stopped, or in some other state. This status information is crucial for understanding the health of your applications.
  • Resource Monitoring: docker ps displays essential resource usage metrics such as CPU and memory utilization. Monitoring these metrics helps optimize the performance of your containers and ensures efficient resource allocation.
  • Port Mapping: It reveals the mapping of container ports to host ports, allowing you to identify which services are exposed and accessible from outside the containerized environment.
  • Health Check: Docker containers can have health checks defined, and docker ps can filter containers based on their health status. This feature ensures that you are aware of the health of your applications and can take necessary actions if any container is unhealthy.
  • Troubleshooting: When something goes wrong with a container, docker ps helps identify the problematic container quickly. It provides crucial information like container IDs and statuses, aiding in rapid troubleshooting and issue resolution.
  • Integration with Automation: docker ps output can be integrated into scripts and automation tools, allowing for seamless integration with continuous integration and continuous deployment (CI/CD) pipelines.
  • User-Friendly Interface: Despite its powerful features, docker ps is designed with a user-friendly interface, making it accessible for both beginners and experienced developers. Its straightforward commands and options enhance the overall Docker user experience.

Conclusion

Understanding and mastering docker ps is essential for effective container management. From listing basic containers to diving into advanced filtering and formatting, this guide has covered it all. With Docker, managing containers has never been so efficient. So go ahead, try out these commands, and explore the world of containerization with confidence.

You can always opt for Docker management services from Supportfly if you want smoother docker operations. Our certified server admins make sure that your Docker environment is trouble free. Our consulting services come with 24×7 server support making us the best server management company globally. Contact our team by clicking here to get started.