Service Discovery by Name
In the previous lesson we saw that containers on the same private network can reach each other. Now we see how they actually find each other: by name, via Docker's built-in DNS. The DNS resolves a container's name to its current IP address — and because the IP changes between runs while the name is
A Docker network is like an office intercom: to call a colleague you just say their name, with no need to memorize phone numbers (IP addresses) that change from time to time. And 'localhost' always means 'me myself' — so to call someone else you must say their name.
- service discovery
- The mechanism by which a container finds another service on the same network by name instead of by IP address. In Docker this is done through the internal DNS, which resolves a container name to its current address.
- DNS by name
- Docker's internal service that resolves a container's name to its current IP address, so you can address it by a stable name instead of an IP that may change.
- localhost trap
- Each container has its own localhost, so addressing localhost from inside one container reaches itself and not another container — you must address the other container by its name.