DEV Community

Yash Sonawane
Yash Sonawane

Posted on

Episode 15: Docker Networking — Custom Networks & Real-World Use Cases

In the last episode, we explored Docker’s built-in networking modes: Bridge, Host, and Overlay. Now, let’s go one step further — creating custom networks to give containers more flexibility, better isolation, and cleaner communication. This is where Docker networking becomes truly powerful in real-world projects.


🔹 Why Custom Networks?

By default, containers in the same bridge network can talk to each other via IP addresses. But in larger setups, we want:

  • Service discovery (containers find each other by name).
  • Network isolation (only specific containers can talk).
  • Flexibility (connect/disconnect containers dynamically).

This is where custom networks shine.


🔹 Creating a Custom Network

docker network create my_custom_network
Enter fullscreen mode Exit fullscreen mode

List available networks:

docker network ls
Enter fullscreen mode Exit fullscreen mode

🔹 Running Containers in Custom Networks

docker run -dit --name app1 --network my_custom_network alpine sh
docker run -dit --name app2 --network my_custom_network alpine sh
Enter fullscreen mode Exit fullscreen mode

Now, app1 and app2 can talk to each other using container names, not just IPs:

docker exec -it app1 ping app2
Enter fullscreen mode Exit fullscreen mode

🔹 Connecting Containers to Multiple Networks

You can attach a container to more than one network:

docker network connect my_custom_network app1
docker network connect bridge app1
Enter fullscreen mode Exit fullscreen mode

This is useful when bridging isolated services.


🔹 Real-World Use Case

Imagine you’re running:

  • A database container (private network only).
  • An API container (can access DB + external users).
  • A frontend container (can access API but not DB).

By designing with custom networks, you can enforce this security boundary with ease.


🔹 Hands-On Exercise

  1. Create two networks: backend_net and frontend_net.
  2. Run a database container inside backend_net.
  3. Run an API container in both networks.
  4. Run a frontend container only in frontend_net.
  5. Test communication boundaries.

✅ By now, you know how to design custom networks for real-world Docker applications. This sets the stage for building secure, scalable apps with Docker.


Top comments (0)