Bird
Raised Fist0
Dockerdevops~10 mins

Inspecting container details in Docker - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Inspecting container details
Start: Have running container
↓
Run 'docker ps' to list containers
↓
Choose container ID or name
↓
Run 'docker inspect <container>'
↓
View detailed JSON info about container
↓
Use info for debugging or monitoring
This flow shows how to list running containers, pick one, and inspect its detailed information using Docker commands.
Execution Sample
Docker
docker ps
# Lists running containers

docker inspect my_container
# Shows detailed info about 'my_container'
Lists running containers and then inspects details of a chosen container.
Process Table
StepCommand RunActionOutput Summary
1docker psList running containersShows container IDs, names, status, ports
2docker inspect my_containerGet detailed infoOutputs JSON with config, state, network, mounts
3Parse JSON outputRead container detailsSee IP address, volumes, environment variables
4Use info for troubleshootingApply knowledgeFix issues or monitor container health
5EndNo further commandsInspection complete
💡 Inspection ends after detailed container info is retrieved and reviewed
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
container_listemptylist of running containersunchangedunchangedunchanged
selected_containernonenonemy_containermy_containermy_container
container_detailsnonenoneraw JSON dataparsed JSON dataparsed JSON data
Key Moments - 3 Insights
Why do we run 'docker ps' before 'docker inspect'?
Because 'docker ps' shows which containers are running and their IDs or names, so you know what to inspect. See execution_table step 1 and 2.
What kind of information does 'docker inspect' provide?
'docker inspect' outputs detailed JSON including container config, network settings, and state. This is shown in execution_table step 2 and 3.
Can you inspect a container that is not running?
Yes, 'docker inspect' works on any container by ID or name, running or stopped. But 'docker ps' only lists running containers, so you might need 'docker ps -a' to see all.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what command lists running containers?
Adocker inspect my_container
Bdocker run
Cdocker ps
Ddocker stop
💡 Hint
Check execution_table row 1 under 'Command Run'
At which step do we get the detailed JSON info about the container?
AStep 2
BStep 3
CStep 1
DStep 4
💡 Hint
Look at execution_table row 2 'Action' and 'Output Summary'
If you want to inspect a stopped container, what should you do differently?
AUse 'docker ps' as usual
BUse 'docker ps -a' to list all containers
CRestart the container first
DYou cannot inspect stopped containers
💡 Hint
Refer to key_moments about inspecting stopped containers
Concept Snapshot
docker ps
# Lists running containers

docker inspect <container>
# Shows detailed JSON info about the container

Use 'docker ps -a' to see all containers including stopped ones

Inspect output helps debug and monitor container state
Full Transcript
To inspect container details, first list running containers with 'docker ps'. This shows container IDs and names. Then choose a container and run 'docker inspect <container>' to get detailed JSON info about its configuration, state, network, and mounts. This info helps you understand the container's environment and troubleshoot issues. You can inspect stopped containers by listing all containers with 'docker ps -a'.

Practice

(1/5)
1. What does the command docker inspect CONTAINER do?
easy
A. Shows detailed JSON information about the specified container
B. Starts the specified container
C. Deletes the specified container
D. Lists all running containers

Solution

  1. Step 1: Understand the command purpose

    The docker inspect command is used to get detailed information about Docker objects like containers.
  2. Step 2: Identify the output type

    It returns detailed JSON data about the container's configuration and state.
  3. Final Answer:

    Shows detailed JSON information about the specified container -> Option A
  4. Quick Check:

    docker inspect = detailed JSON info [OK]
Hint: Remember: inspect means see detailed info [OK]
Common Mistakes:
  • Confusing inspect with start or delete commands
  • Expecting a simple list instead of JSON output
  • Using inspect without specifying a container
2. Which of the following is the correct syntax to get only the container's IP address using docker inspect?
easy
A. docker inspect --format='{{.NetworkSettings.IPAddress}}' CONTAINER
B. docker inspect --ip CONTAINER
C. docker inspect -ip CONTAINER
D. docker inspect --format='{{IPAddress}}' CONTAINER

Solution

  1. Step 1: Recall the --format option usage

    The --format flag uses Go templates to extract specific fields from the JSON output.
  2. Step 2: Identify the correct template for IP address

    The IP address is under .NetworkSettings.IPAddress, so the correct syntax is {{.NetworkSettings.IPAddress}}.
  3. Final Answer:

    docker inspect --format='{{.NetworkSettings.IPAddress}}' CONTAINER -> Option A
  4. Quick Check:

    Use --format with correct JSON path [OK]
Hint: Use --format with full JSON path in double braces [OK]
Common Mistakes:
  • Using incorrect flags like --ip or -ip
  • Missing the dot before NetworkSettings in template
  • Not quoting the template string properly
3. Given a container named webapp, what will the command docker inspect --format='{{.State.Status}}' webapp output if the container is running?
medium
A. created
B. paused
C. exited
D. running

Solution

  1. Step 1: Understand the .State.Status field

    The .State.Status field shows the current status of the container, such as running, exited, paused, or created.
  2. Step 2: Match the container state

    If the container is running, the output will be the string running.
  3. Final Answer:

    running -> Option D
  4. Quick Check:

    .State.Status = running when container runs [OK]
Hint: Check .State.Status for container current state [OK]
Common Mistakes:
  • Confusing status with container name or ID
  • Expecting JSON output instead of plain string
  • Using wrong field like .Status instead of .State.Status
4. You run docker inspect --format='{{.Config.Env}}' mycontainer but get an error. What is the most likely cause?
medium
A. The container name is misspelled
B. The format string syntax is incorrect
C. The .Config.Env field does not exist in the container JSON
D. The container is not running

Solution

  1. Step 1: Check the format string syntax

    The .Config.Env field is an array, so printing it directly requires proper formatting.
  2. Step 2: Identify the syntax error

    Using {{.Config.Env}} tries to print an array directly, which causes a template error. You need to format it, for example with {{range .Config.Env}}{{println .}}{{end}}.
  3. Final Answer:

    The format string syntax is incorrect -> Option B
  4. Quick Check:

    Arrays need special formatting in --format [OK]
Hint: Arrays need loops in --format templates [OK]
Common Mistakes:
  • Assuming all fields print directly without formatting
  • Ignoring container name correctness
  • Thinking container must be running to inspect
5. You want to list all container names and their IP addresses in a simple format. Which command correctly achieves this?
hard
A. docker ps -q | xargs -n1 docker inspect --format='{{.Name}} {{.NetworkSettings.IPAddress}}'
B. docker ps --format='{{.Name}} {{.NetworkSettings.IPAddress}}'
C. docker inspect --format='{{.Name}} {{.NetworkSettings.IPAddress}}' $(docker ps -q)
D. docker inspect $(docker ps) --format='{{.Name}} {{.NetworkSettings.IPAddress}}'

Solution

  1. Step 1: Understand how to get container IDs

    docker ps -q lists container IDs only, which can be passed to docker inspect.
  2. Step 2: Use inspect with multiple container IDs and format

    Passing IDs as arguments to docker inspect with --format outputs info for each container. docker inspect --format='{{.Name}} {{.NetworkSettings.IPAddress}}' $(docker ps -q) uses this correctly.
  3. Step 3: Check other options for errors

    docker ps -q | xargs -n1 docker inspect --format='{{.Name}} {{.NetworkSettings.IPAddress}}' uses xargs but may break if container names have spaces. docker ps --format='{{.Name}} {{.NetworkSettings.IPAddress}}' is invalid because docker ps does not support .NetworkSettings.IPAddress. docker inspect $(docker ps) --format='{{.Name}} {{.NetworkSettings.IPAddress}}' uses wrong syntax for docker ps.
  4. Final Answer:

    docker inspect --format='{{.Name}} {{.NetworkSettings.IPAddress}}' $(docker ps -q) -> Option C
  5. Quick Check:

    Use docker inspect with IDs from docker ps -q [OK]
Hint: Use docker inspect with IDs from docker ps -q [OK]
Common Mistakes:
  • Trying to get IP from docker ps directly
  • Using wrong command substitution syntax
  • Not passing container IDs correctly to inspect
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard