Docker is a strong platform for developing, shipping, and running applications in isolated spaces called containers. It is important to list running Docker containers. This helps us manage and watch our applications better. When we know how to list these containers, we can check that our applications are working right and fix any problems that come up.
In this article, we will talk about different ways to list running Docker containers. We will cover the Docker PS command, how to filter and format the output, and how to include stopped containers in our list. We will also look at the information from the Docker PS output. This will help us understand the status of our containers. Here are the main topics we will discuss:
- How Can You List Running Docker Containers Easily?
- What Are the Basic Docker Commands for Listing Containers?
- How to Use Docker PS Command to List Running Containers?
- What Information Can You Get from the Docker PS Output?
- How to Filter and Format the Output of Docker PS?
- How to List All Containers Including Stopped Ones?
- Frequently Asked Questions
For more information about Docker and what it can do, you can check these articles: What is Docker and Why Should You Use It?, What Are Docker Images and How Do They Work?, and What Is a Docker Container and How Does It Operate?.
What Are the Basic Docker Commands for Listing Containers?
To list Docker containers, we mainly use the docker ps
command. We can also use other commands to fit our needs. Here are the
basic commands for listing running containers and all containers:
List Running Containers: This command shows all Docker containers that are running now.
docker ps
List All Containers: If we want to see all containers, even those that are stopped, we use the
-a
flag.docker ps -a
List Containers with Filters: We can filter the output by some criteria using the
--filter
option. For example, to list containers by their status:docker ps --filter "status=exited"
List Containers with Specific Format: If we want to change the output format, we can use the
--format
option. For example, to show only the container IDs and names:docker ps --format "{{.ID}}: {{.Names}}"
List Containers with Detailed Information: If we want more details, like ports, we can add the
--no-trunc
option:docker ps --no-trunc
These commands are important for managing our Docker containers. They help us check their status and details easily. For more information about Docker, we can check What is Docker and Why Should You Use It?.
How to Use Docker PS Command to List Running Containers?
To list running Docker containers, we can use the
docker ps
command. This command gives us important details
about the containers that are active on our Docker host.
Basic Usage
The easiest way to use the command is:
docker ps
This will show us a list of all running containers. We will see their IDs, names, and other useful info.
Common Options
We can add some options to the docker ps
command to make
it better:
-a
: Show all containers. By default, it shows only running ones.-q
: Show only container IDs.--format
: Change the output format using Go templating.
Examples
List All Running Containers:
docker ps
List All Containers (Including Stopped):
docker ps -a
List Only Container IDs:
docker ps -q
Format the Output:
To show only the names and IDs of running containers, we can use:
docker ps --format "{{.ID}}: {{.Names}}"
This command is very helpful for watching and managing our containers well. For more details on Docker commands, we can check articles like What Are the Basic Docker Commands for Listing Containers?.
What Information Can You Get from the Docker PS Output?
The docker ps
command gives us a clear view of the
Docker containers that are running on our system. The default output
shows us some important columns of information:
- CONTAINER ID: This is a special ID for each running container. We can shorten it for easier reading.
- IMAGE: This shows the Docker image that the container was made from.
- COMMAND: This is the command that runs when the container starts.
- CREATED: This tells us when the container was made.
- STATUS: This shows the current state of the container. It can say things like “Up 5 minutes” or “Exited (0) 3 minutes ago”.
- PORTS: This lists the ports that are open and
linked to the host. It shows in the format
host_port:container_port
. - NAMES: This is the name we give to the container. We can use this name in other commands.
We can see this information by running this command:
docker ps
If we need more information about a specific container, we can use
the docker inspect
command with the container ID or
name:
docker inspect <container_id_or_name>
This command gives us detailed JSON output. It contains all the setup details of the container, like network settings, volumes, and environment variables.
For a quick look at what the docker ps
output looks
like, here is an example:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f1d2e3abc45 nginx:latest "nginx -g 'daemon off;'" 10 minutes ago Up 10 minutes 0.0.0.0:80->80/tcp webserver
This basic understanding of the docker ps
output will
help us manage our Docker containers better. We can also use filtering
and formatting options in the docker ps
command for more
help.
How to Filter and Format the Output of Docker PS?
To filter and format the output of the docker ps
command, we can use different options that Docker gives us. This helps
us to show the information we need and makes it easier to manage our
running containers.
Filtering Output
We can filter the container output based on different criteria. This
includes status, name, or ID. We use the --filter
(or
-f
) option for this. Some common filters are:
- Status: Filter by the status of the container.
- Name: Filter by the name of the container.
- ID: Filter by the ID of the container.
For example, to list only running containers, we can run:
docker ps --filter "status=running"
If we want to filter containers by name, we can do this:
docker ps --filter "name=my_container"
Formatting Output
The --format
option helps us control how the output
looks when we use the docker ps
command. We can choose
which fields to show using Go templating.
For example, if we want to show only the container ID and names, we can run:
docker ps --format "{{.ID}}: {{.Names}}"
We can also show more fields, like status and ports:
docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}"
Common Format Options
- table: Show output as a table.
- json: Show output in JSON format.
- Go template: Use Go templating to change how the output looks.
For example, to get the output in JSON format, we can use this command:
docker ps --format "{{json .}}"
By using the filtering and formatting options of the
docker ps
command, we can manage and see the status of our
running Docker containers easily. For more details on managing Docker
containers, we can check this
article.
How to List All Containers Including Stopped Ones?
We can list all Docker containers, even the stopped ones, by using
the docker ps
command with the -a
(or
--all
) option. This command gives us a complete view of all
containers on our system, no matter their state.
Command to List All Containers
docker ps -a
Output Explanation
The output will show a table with these columns:
- CONTAINER ID: This is a unique ID for the container.
- IMAGE: This shows the Docker image that the container is based on.
- COMMAND: This is the command that runs when the container starts.
- CREATED: This tells us how long ago the container was created.
- STATUS: This shows the current status like running or exited.
- PORTS: This shows the ports that are exposed and mapped from the container.
- NAMES: This is the name we gave to the container.
Additional Filtering
We can filter the output based on certain criteria by combining
docker ps -a
with other options:
To filter containers by status, like exited:
docker ps -a -f "status=exited"
To make the output easier to read, we can use the
--format
option:docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Status}}"
This command will show the container ID, name, and status in a nice table.
For more details on managing Docker containers, we can check this Docker Container Management.
Frequently Asked Questions
How can I check if my Docker is running?
To see if Docker is running on our system, we can open the terminal.
Then we type the command docker info
. If Docker is active,
we will see details about our Docker installation. We can also use
docker ps
to list running containers. This way, we know
Docker is working. For more info on Docker and how it works, we can
check our guide on what
is Docker and why should you use it.
What command do I use to list all Docker containers?
To see all Docker containers, even the stopped ones, we use the
command docker ps -a
. This command gives us a full list of
all containers. It shows details like container IDs, names, and their
current status. If we want to learn more about Docker commands, we can
read our article on the basic
Docker commands.
Can I filter the output of Docker ps?
Yes, we can filter the output of the docker ps
command
with different options. For example, we can type
docker ps --filter "status=running"
to show only the
running containers. We can also mix filters to get more specific
results. To learn more about filtering and formatting output, we can
visit our resource on how
to filter and format the output of Docker PS.
How do I see detailed information about a specific Docker container?
To get detailed info about a specific Docker container, we use the
command docker inspect <container_id>
. This command
gives us complete details about the container’s settings, like network
settings and volumes. For more details about managing Docker containers,
we can explore our article on what
is a Docker container and how does it operate.
What is the difference between Docker containers and images?
Docker containers are copies of Docker images that run apps in separate spaces. Images are static files with the app code and its dependencies. Containers are active and can be started, stopped, or removed. To understand these two ideas better, we can read our article on what is a Docker image and how is it different from a container.