0
0
Dockerdevops~5 mins

Docker inspect for detailed info - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you need to see all the details about a running or stopped Docker container or image. Docker inspect shows you this detailed information in a structured way so you can understand how your container or image is configured and running.
When you want to check the IP address or network settings of a running container
When you need to see the exact command a container was started with
When you want to find the mount points or volumes used by a container
When you want to debug why a container is not working by checking its configuration
When you want to see metadata like environment variables or exposed ports of an image
Commands
This command runs an Nginx container in the background, names it 'example-nginx', and maps port 8080 on your computer to port 80 in the container.
Terminal
docker run -d --name example-nginx -p 8080:80 nginx:1.23
Expected OutputExpected
a1b2c3d4e5f67890123456789abcdef0123456789abcdef0123456789abcdef0
-d - Run container in detached mode (in background)
--name - Assign a custom name to the container
-p - Map host port to container port
This command shows detailed JSON information about the 'example-nginx' container, including network settings, volumes, environment variables, and more.
Terminal
docker inspect example-nginx
Expected OutputExpected
[ { "Id": "a1b2c3d4e5f67890123456789abcdef0123456789abcdef0123456789abcdef0", "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, "Error": "", "StartedAt": "2024-06-01T12:00:01.000000000Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Name": "/example-nginx", "Config": { "Hostname": "a1b2c3d4e5f6", "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "nginx", "-g", "daemon off;" ], "Image": "nginx:1.23", "ExposedPorts": { "80/tcp": {} } }, "NetworkSettings": { "Ports": { "80/tcp": [ { "HostIp": "0.0.0.0", "HostPort": "8080" } ] }, "IPAddress": "172.17.0.2" } } ]
This command extracts and shows only the IP address of the 'example-nginx' container using a Go template format.
Terminal
docker inspect --format='{{.NetworkSettings.IPAddress}}' example-nginx
Expected OutputExpected
172.17.0.2
--format - Format output using a Go template to show specific fields
Key Concept

Docker inspect shows all the detailed settings and status of a container or image in JSON format, helping you understand exactly how it is configured and running.

Common Mistakes
Running docker inspect without specifying a container or image name
Docker will return an error because it needs to know which container or image to inspect
Always provide the container name, container ID, or image name after docker inspect
Trying to inspect a container that is not running or does not exist
Docker will return an error or empty output because the container is not found
Check running containers with docker ps or all containers with docker ps -a before inspecting
Not using --format when you want specific info and getting overwhelmed by full JSON output
The full JSON is large and hard to read for simple info like IP address or ports
Use --format with Go templates to extract only the needed fields
Summary
Run a container with a name and port mapping to have a target for inspection.
Use docker inspect with the container name to see detailed JSON info about its configuration and state.
Use docker inspect with --format to extract specific details like IP address in a simple way.