Have you seen the Docker ps command and wondered what it does and how to use it? Join me in this short guide as I explain this all-important Docker command.

I’ll begin by describing the usage (syntax) and options (arguments) of this command. After that, we will explore some examples and use cases.

Let’s begin!

Overview

Overview of Docker ps Command

As you create Docker containers, over time you have a number of them. Moreover, from time to time, you may need to view the containers to get information about them.

This is where the Docker ps command comes in.

This simple command is used to list containers previously started on the local computer.

Why will you want to list containers on the computer?

There are multiple reasons. Firstly, you may want to get the container ID, name or the ports it is mapped to the host.

Getting the ID or name of a stopped container is useful for starting it. We will see how to start a stopped container in the examples section of this guide.

Usage and Options of the Docker ps Command

Usage and Options of the Docker ps CommandUsage and Options of the Docker ps Command

To see the usage and options of the Docker ps command, run the command with the “–help” option.

docker ps --help

See the result of the command in my screenshot below.

Usage and Options of the docker container list CommandUsage and Options of the docker container list Command

As I explained earlier in the guide, we can see that this lists existing Docker containers. In addition to that, it also shows the aliases of the command.

Essentially, the commands – “docker container ls,”docker container list,” “docker container ps” – are the same as “docker ps.”

So, you can use any of the listed commands instead of the common command.

Moving down the result of the help page, you see the available options. When I published this guide in February 2024, the “Docker ps” command had 6 options.

However, I like to highlight the two commonly used options – “-a” or “–all” and “-f.” As you will see in the examples section, when you work with Docker containers you will find the “-a” or “–all” of the “Docker ps” command useful.

This is because it is used to display both running and stopped containers. When you run the “ps” command without the “-a” option, it only returns running containers.

So, if you want to list all containers – including stopped containers – use this option.

Another common parameter is “-f.” This is essentially a search option used to return containers that meet the conditions you specify.

Docker ps Examples

docker container list Examplesdocker container list Examples

Now that we have explained what this Docker command is all about, let’s see how to use it.

As I already hinted, if you run the command without any parameters, it lists only containers that are currently started (STATUS is “Up”).

docker ps

When I ran the command on my Windows computer, it listed two containers.

docker container ls Examplesdocker container ls Examples

But what is I want to see all containers? I will simply include the “-a” or “–all” option as shown in this command.

docker ps -a

I have a long list of containers – most of them stopped or “exited.”

This is not a very pretty list – it is too long!

How about using the “-f” option to list only the containers I need? Let’s say I want to list mysql containers, I will use the command below.

docker ps -a -f name=mysql
list docker containerslist docker containers

How about listing all stopped containers? We can do that too using the “-f status=exited.”

docker ps -f status=exited
The -f option accepts a key=value pair input. For a full list of the keys you can use with this option, see the Filtering (–filter) section of the official Docker document for this command.

Before you go, it is worth showing the aliases of the “Docker ps” command in action. See the screenshot below for how I used the aliases of the commands I used in this guide so far.

docker container ls,docker container listdocker container psdocker container ls,docker container listdocker container ps

Finally, to start a container that isn’t currently running use the “Docker start” command. The command accepts the container name or ID.

Frequently Asked Questions

1. What Does ps Do in Docker?

Running the “Docker ps” command lists containers.

2. Where to Run the Docker ps Command?

Run this command on a terminal. Note that Docker must be installed and the daemon running on the local computer to run a Docker command, including the “ps” command.

3. How Do I See All Docker Containers?

Run the “Docker ps” command with the “-a” option. This option lists running and stopped (“exited”) containers.

4. How Do I Connect to a Docker Container?

To connect (open a terminal) to a Docker container, run the Docker Exec command.

5. How Do I View Docker Images?

To view docker images on your downloaded (pulled) to your computer, run the “Docker images” or “Docker images ls” command.

I hope you enjoyed reading the guide and now know how to use this essential Docker command.

We like to hear from you.

Kindly share your feedback or ask a question using the comments form at the bottom of this page.

Other Useful Resources

  1. docker ps (docker container ls)
  2. bash – ‘docker ps’ output formatting: list only names of running containers – Stack Overflow
  3. docker compose
  4. docker container start

Victor Ashiedu

Source link

You May Also Like

Threads is testing real-time search results

Meta’s Threads app is often described as the company’s competitor to X.…

IF Conjures Up a New Teaser for Its Imaginary Friends

Image: Paramount John Krasinski and Paramount aren’t just bringing sound-seeking aliens to…

Galaxy AI coming to more devices through new One UI 6.1 update

Samsung Electronics Co., Ltd. announced the availability of Galaxy AI features on…

ChoppingBot multifunctional smart scales and chopping board

The ChoppingBot Smart Scales, have been designed to provide users with the…