๐ฌ "Ever wondered how your frontend talks to your backend inside Docker? Or how multiple containers magically connect like best friends at a tech meetup? In this episode, we dive into Docker networking โ simply and visually."
๐ Why Docker Networking Matters
In real-world apps, you donโt just run a single container.
You often run:
- A frontend (React, Vue, etc.)
- A backend (Node, Django, etc.)
- A database (MongoDB, Postgres, etc.)
These containers need to talk to each other, securely and efficiently.
Dockerโs networking system makes this possible.
๐ Types of Docker Networks
Network Type | Use Case |
---|---|
Bridge | Default, isolated container networks |
Host | Uses the host machineโs network directly |
None | No network at all |
Overlay | For multi-host Docker (Swarm, etc.) |
For most use cases (especially Docker Compose), Bridge is what you need.
๐งช Default Bridge Network
When you run containers without specifying a network:
docker run -d --name nginx nginx
Docker connects them to the bridge
network. But by default, containers canโt talk to each other by name here.
Youโd have to use IPs โ not ideal. So letโs fix that.
๐ ๏ธ Create a Custom Bridge Network
docker network create my-network
Now, run containers and attach them:
docker run -d --name backend --network my-network my-backend-image
docker run -d --name frontend --network my-network my-frontend-image
โ
Now frontend
can reach backend
using its container name as hostname.
Example: http://backend:5000
๐งช Real Example: Node App + MongoDB
# Create custom network
docker network create dev-net
# Run MongoDB
docker run -d \
--name mongo \
--network dev-net \
mongo
# Run Node app connected to mongo
docker run -d \
--name app \
--network dev-net \
my-node-app
Inside my-node-app
, you can now connect to Mongo using:
mongodb://mongo:27017
๐ Inspecting Networks
List networks:
docker network ls
Inspect a network:
docker network inspect my-network
๐ช Port Mapping (Host โ Container)
Want to access your app in the browser?
docker run -d -p 8080:3000 my-app
This maps:
- Port 3000 inside the container
- To port 8080 on your machine
Visit: http://localhost:8080
๐ง Key Takeaways
- Use custom bridge networks to let containers talk by name
- Use
--network
when running multi-container apps - Inspect networks to understand connections
๐ฎ Up Next: Docker Compose โ One YAML to Rule Them All
In Episode 8, weโll cover:
- How to run multi-container apps with one command
- Docker Compose file structure
- Real-world project with frontend + backend + DB
๐ฌ Over to You
Have you tried connecting containers via network yet?
Was the custom bridge easier than expected?
Comment below with your Docker networking wins or pain points!
โค๏ธ If this episode made container networking click for you, share it with your dev buddy or team.
๐ฌ Next: โDocker Compose โ Build Multi-Container Apps Like a Bossโ
Top comments (0)