Binding container ports to host ports is all okay if you just have a plain web server that you want to expose to the Internet. Most production systems, however, are made of lots of individual components that are constantly communicating with each other. Components such as the database servers must not be bound to publicly visible IPs, but the containers running the frontend applications still need to discover the database containers and connect to them. Hardcoding a container's IP addresses in the application is neither a clean solution nor will it work because IP addresses are randomly assigned to the containers. So how do we solve this problem? The answer is as follows.
A link can be