This content originally appeared on DEV Community and was authored by Yash Sonawane
“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β
This content originally appeared on DEV Community and was authored by Yash Sonawane