What if your containers could always find each other without you chasing IP addresses?
Why DNS resolution between containers in Docker? - Purpose & Use Cases
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.
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.
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.
docker run --name webapp --link db_container:db mywebapp
# Use IP 172.17.0.2 to connect to dbdocker network create mynet
docker run --net mynet --name db dbimage
docker run --net mynet --name webapp webimage
# Connect to 'db' by nameYour containers can talk to each other easily and reliably, making your app stable and easier to manage.
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.
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.