0
0
Dockerdevops~3 mins

Why DNS resolution between containers in Docker? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if your containers could always find each other without you chasing IP addresses?

The Scenario

Imagine you have several containers running different parts of your app, like a web server and a database. You try to connect them by guessing IP addresses or writing them down manually.

The Problem

This manual way is slow and frustrating because container IPs change every time you restart them. You end up chasing IPs like a detective, and your app breaks often.

The Solution

DNS resolution between containers lets them find each other by simple names, like friends calling each other by name instead of phone numbers. Docker automatically handles this name-to-IP mapping for you.

Before vs After
Before
docker run --name webapp --link db_container:db mywebapp
# Use IP 172.17.0.2 to connect to db
After
docker network create mynet

docker run --net mynet --name db dbimage

docker run --net mynet --name webapp webimage
# Connect to 'db' by name
What It Enables

Your containers can talk to each other easily and reliably, making your app stable and easier to manage.

Real Life Example

A web app container connects to a database container by simply using the database's container name, even if the database restarts and gets a new IP.

Key Takeaways

Manual IP management is error-prone and breaks easily.

DNS resolution lets containers find each other by name automatically.

This makes multi-container apps more stable and easier to run.