🐳 Docker Beginner

What is docker inspect?

Why Interviewers Ask This

Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Docker development. It reveals whether you understand the building blocks that more complex concepts rely on.

Answer

docker inspect returns detailed low-level information about Docker objects (containers, images, networks, volumes) in JSON format. It is invaluable for debugging. For containers: docker inspect mycontainer — returns a large JSON object including: (1) container ID, name, state (running, exit code, started/finished time); (2) network configuration (IP addresses, ports, gateway); (3) mounted volumes and their host paths; (4) environment variables; (5) resource limits (CPU, memory); (6) restart policy; (7) labels. Extract specific fields with --format using Go template syntax: docker inspect --format "{{.NetworkSettings.IPAddress}}" mycontainer — get container IP; docker inspect --format "{{.State.ExitCode}}" mycontainer — get exit code; docker inspect --format "{{json .Config.Env}}" mycontainer — get env vars as JSON. For images: docker inspect nginx:1.25 — shows layers, config, exposed ports, architecture. For networks: docker inspect mynetwork — shows connected containers and their IPs. For volumes: docker inspect myvolume — shows mount point on host. Use docker inspect when debugging: container can't connect to another service (check IPs and networks), env vars not set correctly, volume not mounted at expected path.

Pro Tip

This topic has Docker-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.