0
0
Dockerdevops~30 mins

Why container networking matters in Docker - See It in Action

Choose your learning style9 modes available
Why container networking matters
📖 Scenario: You are working on a small project where two Docker containers need to talk to each other. One container runs a simple web server, and the other container will send requests to it. To make this communication possible, you need to set up container networking correctly.
🎯 Goal: Learn how to create a Docker network and connect two containers so they can communicate. You will create a network, run two containers attached to that network, and verify they can reach each other.
📋 What You'll Learn
Create a Docker network named my_network
Run a container named web_server using the nginx image attached to my_network
Run a container named client using the alpine image attached to my_network
Use the ping command inside the client container to check connectivity to web_server
💡 Why This Matters
🌍 Real World
In real projects, containers often need to communicate, like a web app talking to a database. Setting up container networking correctly makes this possible.
💼 Career
Understanding container networking is essential for DevOps roles, as it helps manage microservices and containerized applications efficiently.
Progress0 / 4 steps
1
Create a Docker network
Create a Docker network called my_network using the docker network create command.
Docker
Need a hint?

Use the command docker network create my_network to create a new network.

2
Run the web server container on the network
Run a container named web_server using the nginx image. Attach it to the my_network network using the --network option.
Docker
Need a hint?

Use docker run -d --name web_server --network my_network nginx to start the web server container.

3
Run the client container on the network
Run a container named client using the alpine image. Attach it to the my_network network using the --network option. Start it with an interactive shell using sh.
Docker
Need a hint?

Use docker run -it --name client --network my_network alpine sh to start the client container with a shell.

4
Test connectivity from client to web server
Inside the client container shell, run the command ping -c 3 web_server to check if the client can reach the web server container by its name.
Docker
Need a hint?

Use ping -c 3 web_server inside the client container to test connectivity.