How do you check a container's IP address, environment variables and resource usage?
docker inspect shows full JSON details such as IP, env vars, mounts and state, and -f with a Go template pulls out one field. docker stats shows live CPU, memory and network usage.
Explain it simply
docker inspect is the Aadhaar record of a container: every detail registered about it. docker stats is the live heart-rate monitor.
Inspect prints a large JSON document: network settings and IP, environment variables, mounts, restart policy, exit code and more. Reading it all is slow, so pass -f with a Go template to pick one field. docker stats streams CPU percent, memory used against the limit, network I/O and process count for running containers, refreshing every second. --no-stream prints one snapshot. docker top web lists the processes inside, and docker port web shows published ports.
These are the first tools to reach for when a container is slow, memory-hungry or unreachable.
Example
docker inspect web | less
docker inspect -f '{{.NetworkSettings.IPAddress}}' web
docker inspect -f '{{json .Config.Env}}' web
docker stats --no-stream
docker top webWhat to say in the interview
"docker inspect gives the full JSON for a container and I use -f with a template to extract a field like the IP or env vars. docker stats gives live CPU and memory use, and docker top lists its processes."
Common mistakes
- Reading the IP of the default bridge and hard-coding it; it changes on restart, use names on a user-defined network.