How do containers on the same host talk to each other?

Put them on a user-defined bridge network; Docker provides DNS so they reach each other by container name.

bash docker network create app docker run -d --name db --network app postgres docker run -d --network app myapp connects to host "db"