What is docker inspect?
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.
Previous
What is the HEALTHCHECK instruction in Dockerfile?
Next
What is docker pull and docker push?