0
0
Dockerdevops~15 mins

Inspecting container network settings in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Inspecting container network settings
📖 Scenario: You are working with Docker containers and want to understand how they connect to networks. This helps you see which IP addresses and ports your containers use, just like checking the address and phone number of a house.
🎯 Goal: You will create a Docker container, check its network settings, and display the IP address assigned to it.
📋 What You'll Learn
Create a Docker container running the nginx image with the name mynginx
Use the docker inspect command to get network details of the container
Extract the IP address from the network settings
Print the IP address to the terminal
💡 Why This Matters
🌍 Real World
Knowing container network settings helps when you want to connect containers to each other or to your computer, like knowing the address to send mail or call a friend.
💼 Career
DevOps engineers often inspect container networks to troubleshoot connectivity issues and configure services correctly.
Progress0 / 4 steps
1
Create a Docker container named mynginx
Run the command docker run -d --name mynginx nginx to create and start a container named mynginx using the nginx image.
Docker
Need a hint?

This command downloads the nginx image if needed and runs it in the background with the name mynginx.

2
Inspect the container mynginx to get network details
Run the command docker inspect mynginx to see detailed information about the container, including its network settings.
Docker
Need a hint?

This command shows a lot of details in JSON format about the container.

3
Extract the IP address from the container's network settings
Run the command docker inspect -f '{{ .NetworkSettings.Networks.bridge.IPAddress }}' mynginx to get only the IP address of the container.
Docker
Need a hint?

The -f option formats the output to show only the IP address.

4
Display the IP address of the container
Run the command docker inspect -f '{{ .NetworkSettings.Networks.bridge.IPAddress }}' mynginx and observe the output which shows the container's IP address.
Docker
Need a hint?

The output should be an IP address starting with 172. or similar, showing the container's network address.