0
0
Dockerdevops~5 mins

Inspecting container details in Docker - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you need to see what is happening inside a running container or check its settings. Inspecting container details helps you understand its status, configuration, and resource usage.
When you want to check the IP address or network settings of a running container
When you need to see environment variables or volumes attached to a container
When you want to verify the container's current state and resource limits
When debugging why a container is not behaving as expected
When you want to see logs or the command used to start the container
Commands
This command lists all running containers so you can find the container ID or name to inspect.
Terminal
docker ps
Expected OutputExpected
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b1f3c2a4d5e6 nginx:1.23.3 "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:8080->80/tcp example-nginx
-a - Show all containers, including stopped ones
This command shows detailed JSON information about the container named 'example-nginx', including network, volumes, and environment variables.
Terminal
docker inspect example-nginx
Expected OutputExpected
[ { "Id": "b1f3c2a4d5e6f7g8h9i0jklmnopqrstuv", "Created": "2024-06-01T12:00:00.000000000Z", "Path": "/docker-entrypoint.sh", "Args": ["nginx", "-g", "daemon off;"], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 12345, "ExitCode": 0, "StartedAt": "2024-06-01T12:00:05.000000000Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:abcdef1234567890", "NetworkSettings": { "IPAddress": "172.17.0.2", "Ports": { "80/tcp": [ { "HostIp": "0.0.0.0", "HostPort": "8080" } ] } }, "Mounts": [] } ]
This command shows the logs output by the container, useful for debugging or checking what the container is doing.
Terminal
docker logs example-nginx
Expected OutputExpected
172.17.0.1 - - [01/Jun/2024:12:01:00 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.68.0"
-f - Follow the log output live
Key Concept

If you remember nothing else from this pattern, remember: docker inspect shows all the detailed settings and state of a container in JSON format.

Common Mistakes
Trying to inspect a container using its image name instead of container name or ID
docker inspect requires a container name or ID, not an image name, so it will fail or show wrong info
Use 'docker ps' to find the container name or ID, then run 'docker inspect' with that name or ID
Running 'docker logs' on a container that is not running
If the container is stopped or does not exist, logs command will fail or show no output
Check container status with 'docker ps -a' before running logs
Summary
Use 'docker ps' to list running containers and find the container name or ID.
Use 'docker inspect <container>' to see detailed JSON info about the container's settings and state.
Use 'docker logs <container>' to view the container's output logs for debugging.