Allow Containers to Communicate through Docker Networks

Joel Lord
InstructorJoel Lord

Share this video with your friends

Send Tweet

In the last lesson Create a Custom Image with a Dockerfile running Node.js, our backend stopped working again because it couldn’t find the database.

One of the advantages of running containers is that they run in isolation. As far as the container is concerned, nothing exists outside of it. It behaves as if it was its own operating system. This is why the backend can’t find the database on "localhost". The two containers are running on the same host but as far as the backend is concerned, there is no database. The same goes for the database. It can’t see anything outside of what is running in its container therefore it can’t see the backend application running.

When you need a way for multiple containers to talk to each other, Docker has a tool called networks to help you. We'll use a network to allow our backend to successfully connect to the database.