Container to Container communication: ID vs public hostname

I am doing some container to container communication. Container ‘A’ has port 80 exposed publicly and container ‘B’ is on the same (docker) network and is making a request.

In this situation I can use the docker container ID in the url for the request, or the public hostname of the actual machine (since port 80 of container A has been forwarded).

I am not sure which name I should be using to make the request though - any help on which one is preferable and why would be appreciated!

How do you start your container? docker run, docker-compose, docker stack deploy?
Please share the exact commands or docker-compose.yml files.

We are using docker-compose

Service names and declared network aliases result in dns entries in the docker network that can be used to lookup containers. Either one of them is what you want to use :slight_smile: