Module 69: Docker

Lesson 4 of 5 · 15–25 minutes

Networking

🏠The everyday picture

Phones on an office's internal exchange can call each other by extension name; only the reception line connects to the outside world.

📘What it really is

🖱️Try it

Create a network crm-net. Run the database container on it with the name db (no published port), and your API container on it with DATABASE_URL pointing at db, publishing the API on 127.0.0.1:3001 only. Check the API works at http://localhost:3001/health, and that the database isn't reachable from your host on 5432.

✅Quick check

How does the API container find the database container on the same network?

Show the answer

By the database container's name, used as the host name.

Why publish the API as 127.0.0.1:3001:3001 instead of 3001:3001?

Show the answer

So it's only reachable from the host (and Nginx), not from the internet, and can't bypass the firewall.

← PreviousVolumes and data
ProLearners Assist