The way to do this today is Docker Networking.
The short version is that you can run docker network ls
to get a listing of your networks. By default, you should have one called bridge
. You can either create a new one or use this one by passing --net=bridge
when creating your container. From there, containers launched with the same network can communicate with each other over exposed ports.
If you use Docker Compose as has been mentioned, it will create a bridge network for you when you run docker-compose up
with a name matching the folder of your project and _default
appended. Each image defined in the Compose file will get launched in this network automatically.
With all that said, I’m guessing your frontend is a webserver that just serves up the HTML/JS/CSS and those pages access the backend service. If that’s accurate, you don’t really need container-to-container communication in this case anyway… both need to be exposed to the host since connections originate from the client system.