Checking the Status of Docker Containers
Monitoring the status of Docker containers is an essential task for developers and system administrators. Docker provides several commands to help you check the status of your containers, including:
docker ps
The docker ps
command is the most commonly used command to list all running containers. It displays information such as the container ID, image, command, creation time, status, and ports.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
abc123def456 nginx:latest "nginx -g..." 5 minutes ago Up 5 minutes 80/tcp
docker inspect
The docker inspect
command provides detailed information about a specific container, including its configuration, network settings, and runtime status.
$ docker inspect abc123def456
[
{
"Id": "abc123def456...",
"Created": "2023-04-12T12:34:56.789Z",
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 12345,
"ExitCode": 0,
"Error": "",
"StartedAt": "2023-04-12T12:34:56.789Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
// ... additional container details
}
]
docker stats
The docker stats
command provides real-time information about the resource usage of one or more running containers, including CPU, memory, network, and block I/O utilization.
$ docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
abc123def456 nginx 0.07% 2.746MiB / 7.704GiB 0.04% 648B / 648B 0B / 0B 2
By using these Docker commands, you can effectively monitor the status and resource usage of your Docker containers, helping you to identify and troubleshoot any issues that may arise.