Bird
Raised Fist0
Dockerdevops~20 mins

Inspecting container network settings in Docker - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Network Inspector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Inspect the IP address of a running container
You have a running Docker container named webapp. Which command will show you the container's IP address?
Adocker network inspect webapp
Bdocker logs webapp | grep IP
Cdocker ps -q webapp
Ddocker inspect -f '{{ .NetworkSettings.IPAddress }}' webapp
Attempts:
2 left
💡 Hint
Use the docker inspect command with a format option to get specific network info.
💻 Command Output
intermediate
2:00remaining
Check which network a container is connected to
You want to find out which Docker networks the container dbserver is connected to. Which command gives you this information?
Adocker inspect -f '{{ json .NetworkSettings.Networks }}' dbserver
Bdocker network inspect dbserver
Cdocker network ls dbserver
Ddocker ps --filter network=dbserver
Attempts:
2 left
💡 Hint
Look inside the container's network settings using docker inspect with a format.
❓ Troubleshoot
advanced
3:00remaining
Diagnose why a container cannot reach another container by name
Two containers, frontend and backend, are running on the default bridge network. The frontend container cannot ping backend by its container name. What is the most likely reason?
AThe backend container is stopped, so it cannot respond to pings.
BContainers on the default bridge network cannot resolve each other's names; user-defined networks are needed for name resolution.
CThe frontend container's firewall is blocking ICMP packets.
DDocker daemon is not running, so containers cannot communicate.
Attempts:
2 left
💡 Hint
Think about how Docker handles DNS resolution on different network types.
❓ Configuration
advanced
3:00remaining
Configure a container to use a specific static IP address
You want to run a container with a fixed IP address 172.18.0.50 on a user-defined network named mynetwork. Which command correctly assigns this IP?
Adocker network create --subnet=172.18.0.0/16 mynetwork && docker run --net mynetwork --ip 172.18.0.50 alpine
Bdocker run --net mynetwork --ip 172.18.0.50 alpine
Cdocker network create mynetwork && docker run --net mynetwork --ip 172.18.0.50 alpine
Ddocker run --ip 172.18.0.50 alpine
Attempts:
2 left
💡 Hint
You must create the network with a subnet before assigning static IPs.
✅ Best Practice
expert
4:00remaining
Best practice for inspecting container network settings in a multi-host Docker Swarm
In a Docker Swarm cluster with multiple hosts, you want to inspect the network settings of a service's tasks (containers) across nodes. What is the best approach?
AUse <code>docker service inspect [service]</code> to get all network details of tasks directly from the manager node.
BRun <code>docker network inspect [network]</code> on the manager node only to see all container IPs.
CUse <code>docker service ps --no-trunc --filter desired-state=running [service]</code> to list tasks, then <code>docker inspect</code> on each task container ID on its host.
DSSH into each worker node and run <code>docker ps</code> to find containers, then <code>docker logs</code> for network info.
Attempts:
2 left
💡 Hint
Consider how Docker Swarm distributes containers and where you can run commands.

Practice

(1/5)
1. Which Docker command shows detailed information about a specific network, including connected containers?
easy
A. docker ps
B. docker container inspect <container_id>
C. docker network inspect <network_name>
D. docker network ls

Solution

  1. Step 1: Understand the purpose of docker network inspect

    This command provides detailed info about a Docker network, including which containers are connected.
  2. Step 2: Compare with other commands

    docker container inspect shows container details, docker ps lists running containers, and docker network ls lists networks without details.
  3. Final Answer:

    docker network inspect <network_name> -> Option C
  4. Quick Check:

    Network details = docker network inspect [OK]
Hint: Use docker network inspect for network details [OK]
Common Mistakes:
  • Confusing container inspect with network inspect
  • Using docker ps to get network info
  • Using docker network ls for detailed info
2. Which of the following commands correctly shows the IP address of a running container named webapp using docker container inspect with formatting?
easy
A. docker container inspect --format '{{.NetworkSettings.IPAddress}}' webapp
B. docker container inspect --format '{{.Network.IP}}' webapp
C. docker inspect --format '{{.NetworkSettings.IP}}' webapp
D. docker container inspect --format '{{.IPAddress}}' webapp

Solution

  1. Step 1: Identify correct JSON path for IP address

    The IP address is under .NetworkSettings.IPAddress in container inspect output.
  2. Step 2: Check command syntax

    docker container inspect --format '{{.NetworkSettings.IPAddress}}' webapp uses correct command and format string. Others use incorrect paths or omit 'container'.
  3. Final Answer:

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

    IP address path = .NetworkSettings.IPAddress [OK]
Hint: Use .NetworkSettings.IPAddress to get container IP [OK]
Common Mistakes:
  • Using wrong JSON path like .Network.IP
  • Omitting 'container' in the command
  • Using '{{.IPAddress}}' which is invalid
3. Given a container named db connected to a network backend_net, what will the command docker network inspect backend_net show about the container?
medium
A. It lists the container ID and its IPv4 address inside the network.
B. It shows only the container name without IP details.
C. It shows the container's CPU and memory usage.
D. It shows the container's logs.

Solution

  1. Step 1: Understand output of docker network inspect

    This command shows network details including connected containers with their IDs and IP addresses.
  2. Step 2: Eliminate incorrect options

    It does not show CPU/memory usage or logs, and it includes IP info, not just names.
  3. Final Answer:

    It lists the container ID and its IPv4 address inside the network. -> Option A
  4. Quick Check:

    Network inspect shows container IDs and IPs [OK]
Hint: Network inspect shows container IDs and IPs connected [OK]
Common Mistakes:
  • Expecting resource usage info from network inspect
  • Thinking it shows logs
  • Assuming only container names appear
4. You run docker container inspect --format '{{.NetworkSettings.IPAddress}}' myapp but get an empty output. What is the most likely reason?
medium
A. The container myapp is not connected to the default bridge network.
B. Docker daemon is not running.
C. The command syntax is incorrect.
D. The container myapp is stopped.

Solution

  1. Step 1: Understand when IPAddress is empty

    If a container is stopped, it has no active network interface, so IPAddress is empty.
  2. Step 2: Check other options

    Not connected to default network still shows IP if connected elsewhere; syntax is correct; daemon not running causes errors, not empty output.
  3. Final Answer:

    The container myapp is stopped. -> Option D
  4. Quick Check:

    Stopped container IP is empty [OK]
Hint: Empty IP means container likely stopped [OK]
Common Mistakes:
  • Assuming wrong syntax causes empty output
  • Thinking network choice causes empty IP
  • Ignoring container running state
5. You want to list all containers connected to a custom network mynet and show their names and IP addresses in a simple table. Which approach is best?
hard
A. Run docker ps and guess which containers belong to mynet.
B. Use docker network inspect mynet and parse the JSON to extract container names and IPs.
C. Use docker container inspect --format '{{.Name}} {{.NetworkSettings.IPAddress}}' on all containers and filter manually.
D. Restart Docker daemon to refresh network info.

Solution

  1. Step 1: Identify command that shows network container info

    docker network inspect mynet lists all containers connected with their IPs.
  2. Step 2: Understand why other options are less effective

    docker ps doesn't show network info; inspecting all containers is manual and error-prone; restarting daemon is unrelated.
  3. Final Answer:

    Use docker network inspect mynet and parse the JSON to extract container names and IPs. -> Option B
  4. Quick Check:

    Network inspect shows connected containers best [OK]
Hint: Use docker network inspect to get connected containers easily [OK]
Common Mistakes:
  • Using docker ps to find network info
  • Inspecting containers individually without filtering
  • Restarting daemon unnecessarily
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