CD2: Running many containers together

Lesson 1 of 5 · reading 15–25 minutes; practice and project time is on the module page

Networks and names

🎯You'll be able to

Put containers on a private network where they find each other by name, and decide which ports, if any, are published to the outside.

🏠The everyday picture

In an office building, colleagues call each other on short internal extensions ("dial 214 for accounts"). Only the reception desk has a number that outsiders can call. Nobody gives the accounts team's extension to the public.

📘What it really is

📝A worked example

Input: in the RouteRani kit, terraform apply in infra/, then docker network inspect routerani-dev and docker exec routerani-dev-lb nslookup app 127.0.0.11.

Expected output: the network lists the database, the API copies and the load balancer. The lookup returns one address per API copy (two once Project 1 adds a second copy). docker port routerani-dev-db shows 5432/tcp -> 0.0.0.0:15432 in the starter, meaning anyone who can reach your computer can try to sign in to the database. Project 1 removes that.

🌍Where it's used

📝Case scenario

A coaching institute's student portal ran PostgreSQL in Docker with -p 5432:5432 "just for debugging", on a cloud server with a public address. Automated scanners found it within hours and tried thousands of passwords. Because the password was postgres123, they got in and copied the student list. A private network, no published port and a strong generated password would each have stopped it.

🖱️Try it

Run docker run --rm --network routerani-dev alpine nslookup db and then the same with --network bridge. Success: the first finds db, the second can't, because only user-defined networks have the name lookup.

⚠️Common mistakes

🛠️For your project

Project 1 test 6 fails if the database container has any port published on your computer.

✅Quick check

How does the RouteRani API find the database?

Show the answer

By the name db, which Docker's DNS answers on the shared network.

What does -p 127.0.0.1:8080:80 change compared with -p 8080:80?

Show the answer

Only the host itself can reach port 8080, not other computers.

← BackCD2
ProLearners Assist