JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM > Docker >

Check if the Docker container is running

Author:JIYIK Last Updated:2025/03/25 Views:

In Docker, there are multiple ways to check the status of a container. When displaying this information, we can also check if the Docker container is running.

This article will discuss the commands to check if a Docker container is running.


Check if the Docker container is running

In Docker, we have multiple commands to check the status of all created containers. In the next section, we will list various examples of these commands.

docker ps

In Docker, we have a docker pscommand called which lists all containers. If you have received Docker training, docker ps may have become a part of the basic Docker lifecycle.

docker psThe command has several options; however, the two most important ones will be discussed in this section.

The first is the --all or -a option to the command that shows all containers. By default, running the command without the -a option will only show the running containers.

Sample code:

docker ps -a
docker ps

Output:

Running docker ps a

Furthermore, we can use an additional option to only show running containers. For example, we can use the --filter option to only find containers with status equal to running.

Sample code:

docker ps -a --filter status=running

Output:

running docker ps a with filter

The above command is similar to docker container ls -athe command, which lists all containers and their status at the container level.

Bash and docker inspect

Another method we can use to display a running container is programmatically. For example, we can use docker inspect to list the properties of a container.

Since the above command has a JSON output, we can use it with bash.

Sample code:

if [ $(docker inspect -f '{{.State.Running}}' "zen_dirac") = "true" ]; then echo Running; else echo NotRunning; fi

The following code snippet searches for a specific container named zen_dirac and its State.Running property. If the property is equal to True, the command will display the final output Running, otherwise it will display NotRunning.

This code snippet can be helpful if we are managing hundreds of running containers and only need information about a single container. In this case, our zen_dirac container is running, so it should produce the output of Running in our command line.

Output:

Running

docker info

Additionally, if we need a high-level summary report of the containers, we can use docker infothe command. docker infoThe command displays system-wide information, including several running containers.

This command is useful if we don’t need to enter the name of the container but want to check if the container is running.

Sample code:

docker info

Output:

docker info

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Copy files from host to Docker container

Publish Date:2025/03/25 Views:126 Category:Docker

This article will discuss and demonstrate methods we can use to transfer files from the host to a running container in Docker. docker cp Copy the file from the host to the Docker container using docker cp The command is one of the simplest

Get the IP address of the Docker container

Publish Date:2025/03/25 Views:102 Category:Docker

This article demonstrates how to get the IP address of a Docker container. Connect to the Bridge network and get the IP address of the Docker container One of the big reasons why docker containers are so convenient is that we can easily con

Uninstalling Docker on macOS

Publish Date:2025/03/25 Views:95 Category:Docker

Recently, we have seen widespread adoption of Docker as the ultimate containerization platform. Because of this, setting up Docker on all platforms has been greatly simplified, including macOS and Windows. However, some users usually face p

Enter the Docker container's shell

Publish Date:2025/03/25 Views:98 Category:Docker

This article will demonstrate how to enter the Docker container shell using multiple methods. Use docker exec to enter the Docker container's shell We need to have a container up and running to use this command. We can check the status of t

Listing containers in Docker

Publish Date:2025/03/25 Views:122 Category:Docker

This article will discuss various commands for listing containers created in our system. This means we should create some containers beforehand for these commands to return values. List all running containers in Docker We will start by list

Mount the host directory into the Docker container

Publish Date:2025/03/25 Views:189 Category:Docker

Docker provides, among other features, tools to work with the host operating system and the container file system. One of these features is the ability to persist data in containers and share data between containers by mounting directories

Docker build command with multiple parameters

Publish Date:2025/03/25 Views:138 Category:Docker

docker build The command allows us to create a Docker image from a Dockerfile. It also allows us to build an image from a context that references a set of files located in a location specified by a PATH or URL. A Dockerfile, on the other ha

The difference between CMD and ENTRYPOINT in Docker

Publish Date:2025/03/25 Views:141 Category:Docker

Docker containers have become the standard when it comes to managing software and dependencies in different environments. When working with real-world applications, you need to create a docker file before building your application container

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial