Overview of Docker Inspection Commands
Docker provides multiple powerful commands to inspect container details, helping developers and system administrators understand container configurations, performance, and runtime characteristics.
Key Docker Inspection Commands
1. docker inspect
The most comprehensive command for retrieving detailed container information.
docker inspect <container_id_or_name>
## Get container IP address
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_name>
## Get container state
docker inspect -f '{{.State.Status}}' <container_name>
2. docker ps
Lists running and stopped containers with basic information.
## List running containers
docker ps
## List all containers
docker ps -a
## Show container size
docker ps -s
3. docker logs
Retrieves container logs for troubleshooting and monitoring.
## View container logs
docker logs <container_name>
## Follow log output in real-time
docker logs -f <container_name>
## Show last 50 log entries
docker logs --tail 50 <container_name>
docker top
Shows processes running inside a container.
docker top <container_name>
docker stats
Provides real-time resource usage statistics.
## Live resource monitoring
docker stats <container_name>
## Monitor all containers
docker stats
Comparison of Inspection Commands
Command |
Purpose |
Detail Level |
Performance Impact |
docker inspect |
Comprehensive container details |
High |
Low |
docker ps |
Container list |
Medium |
Very Low |
docker logs |
Container logs |
Medium |
Low |
docker top |
Running processes |
Low |
Low |
docker stats |
Resource usage |
Real-time |
Medium |
JSON Output
docker inspect --format='{{json .}}' <container_name>
docker inspect --format='Container Name: {{.Name}}, IP: {{.NetworkSettings.IPAddress}}' <container_name>
Workflow Visualization
graph TD
A[Docker Container] --> B{Inspection Command}
B -->|docker inspect| C[Detailed Configuration]
B -->|docker ps| D[Container List]
B -->|docker logs| E[Container Logs]
B -->|docker top| F[Running Processes]
B -->|docker stats| G[Resource Usage]
LabEx Learning Tip
LabEx provides interactive labs that allow you to practice these Docker inspection techniques in a hands-on, real-world environment, helping you master container management skills.
Best Practices
- Use appropriate commands for specific information needs
- Combine commands for comprehensive insights
- Understand output formats and filtering options
- Regularly monitor container performance and logs