Identifying Running Containers by ID
One way to identify a running Docker container is by its unique container ID. The container ID is a long, hexadecimal string that uniquely identifies the container.
Listing Running Containers by ID
You can use the docker ps
command to list all running containers and their IDs. This command will display a table with information about each running container, including the container ID, the image used to create the container, the command being executed, the time the container was created, the status of the container, and the names of the container.
docker ps
This will output a table similar to the following:
CONTAINER ID |
IMAGE |
COMMAND |
CREATED |
STATUS |
PORTS |
NAMES |
1234567890ab |
ubuntu:22.04 |
"/bin/bash" |
5 minutes ago |
Up 5 minutes |
|
loving_einstein |
In this example, the container ID is 1234567890ab
.
Accessing a Container by ID
Once you have the container ID, you can use it to interact with the container. For example, you can attach to the container's terminal using the docker attach
command:
docker attach 1234567890ab
This will attach your terminal to the running container, allowing you to interact with it directly.
You can also use the container ID to stop, start, or remove the container using the docker stop
, docker start
, and docker rm
commands, respectively.
## Stop the container
docker stop 1234567890ab
## Start the container
docker start 1234567890ab
## Remove the container
docker rm 1234567890ab
By using the container ID, you can easily identify and manage your running Docker containers.