0
0
Dockerdevops~30 mins

Container DNS and service discovery in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Container DNS and Service Discovery with Docker
📖 Scenario: You are setting up a small Docker network where two containers can find each other by name. This is like having two friends in a room who can call each other by their names instead of phone numbers.We will create two containers: a simple web server and a client that will ping the server using its container name. This shows how Docker's built-in DNS helps containers discover each other easily.
🎯 Goal: Build a Docker network with two containers named webserver and client. The client container will use the container name webserver to ping and confirm it can reach the webserver container using Docker's DNS service discovery.
📋 What You'll Learn
Create a Docker network named my_network
Run a container named webserver using the nginx image connected to my_network
Run a container named client connected to my_network
Use the ping command inside the client container to ping webserver
Display the ping result to confirm connectivity
💡 Why This Matters
🌍 Real World
In real projects, containers need to find and talk to each other easily. Docker's DNS service discovery lets containers use simple names instead of IP addresses, making communication reliable and easier to manage.
💼 Career
Understanding container networking and service discovery is essential for DevOps roles, cloud engineers, and developers working with microservices and container orchestration.
Progress0 / 4 steps
1
Create a Docker network
Create a Docker network called my_network using the command docker network create my_network.
Docker
Need a hint?

Think of a Docker network as a private room where containers can talk to each other by name.

2
Run the webserver container on the network
Run a container named webserver using the nginx image connected to the my_network network with the command docker run -d --name webserver --network my_network nginx.
Docker
Need a hint?

Use --name to name the container and --network to connect it to the network.

3
Run the client container on the network
Run a container named client connected to the my_network network using the alpine image with the command docker run -it --rm --name client --network my_network alpine sh. Then install ping inside the container with apk add --no-cache iputils.
Docker
Need a hint?

The alpine image is small and you need to add ping manually using apk.

4
Ping the webserver container from the client
Inside the client container shell, run the command ping -c 3 webserver to send 3 ping requests to the webserver container and confirm connectivity.
Docker
Need a hint?

If you see lines starting with PING webserver and replies, it means the client found the webserver by name.