In Docker, you can get the container ID of a running container using the docker ps
command. This command lists all running containers along with their container IDs.
The following example shows how to retrieve the container ID of a Docker container.
How to Get the Container ID of a Running Docker Container
We can use the docker ps
command to get the container ID of a running Docker container.
Suppose we would like to view the container ID of all currently running Docker containers.
We can run the following command in the terminal:
docker ps
Output: 👇️
In this example, the docker ps
command lists all running containers with details such as container ID, image, command, creation time, status, ports, and names.
The CONTAINER ID
column shows the ID of each running container.
For example, in the above screenshot, we can see that postgres
container has a173b2cb4c4c container id.
How to Get the Container ID of All Docker Containers (Including Stopped)
We can use the docker ps- a
command to get the container ID of all containers, including stopped ones.
Suppose we would like to see the container ID of all containers, regardless of their status.
We can use the following command in the terminal:
docker ps -a
Output: 👇️
In this example, the docker ps -a
command lists all containers, including those that have stopped.
The CONTAINER ID
column shows the ID of each container. We can see that the docker image with container ID 87080cf4cc1c is in the stopped state and others are running.
Conclusion
We can use the docker ps
command to get the container ID of running containers and the docker ps -a
command to get the container ID of all containers, including stopped ones.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.