0
0
Dockerdevops~30 mins

DNS resolution between containers in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
DNS resolution between containers
📖 Scenario: You are setting up two Docker containers that need to talk to each other by name. This is common when you have multiple services working together, like a web app and a database.Docker allows containers to find each other by their container names if they are on the same network. You will create two containers, connect them to a user-defined network, and test that one container can reach the other by its name.
🎯 Goal: Build two Docker containers connected on the same network and verify that one container can resolve the other's name using DNS.
📋 What You'll Learn
Create a user-defined Docker network called my_network
Run two containers named container1 and container2 connected to my_network
Use the alpine image for both containers
Test DNS resolution inside container1 to reach container2 by name
💡 Why This Matters
🌍 Real World
In real projects, services like databases and web servers run in separate containers. They need to find each other by name to work together.
💼 Career
Understanding container networking and DNS resolution is essential for DevOps roles managing microservices and containerized applications.
Progress0 / 4 steps
1
Create a user-defined 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 the network.

2
Run two containers connected to the network
Run two containers named container1 and container2 using the alpine image. Connect both containers to the my_network network. Use the --rm flag to remove containers after exit and run them in detached mode with -d. Use sleep 300 as the command to keep containers running.
Docker
Need a hint?

Use docker run -d --rm --name container1 --network my_network alpine sleep 300 and similarly for container2.

3
Test DNS resolution from container1 to container2
Use docker exec to run the ping -c 1 container2 command inside container1 to test if container2 can be resolved by name.
Docker
Need a hint?

Use docker exec container1 ping -c 1 container2 to test DNS resolution.

4
Verify the ping output shows successful DNS resolution
Run the full command to ping container2 from container1 and verify the output contains 1 packets transmitted, 1 packets received indicating successful DNS resolution.
Docker
Need a hint?

Look for the line 1 packets transmitted, 1 packets received in the ping output.