Custom Bridge Networks and Service Discovery
Create user-defined bridge networks so containers can find and talk to each other by name, and learn how Docker handles DNS-based service discovery.
Custom Bridge Networks and Service Discovery is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 4 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.
Why a Custom Network?
The default bridge network works, but containers on it can only reach each other by IP address. A user-defined bridge network adds automatic DNS-based service discovery so containers reach each other by name.
- Better isolation between app groups
- Built-in name resolution
- Containers can be attached and detached on the fly
Listing Existing Networks
Docker ships with three default networks. Inspect them with docker network ls before creating your own.
docker network lsCreating a Bridge Network
Use docker network create. Without a driver flag Docker defaults to the bridge driver, ideal for single-host containers.
docker network create app-netInspecting the Network
docker network inspect shows the subnet, gateway, and any attached containers as JSON. Handy for debugging IP ranges.
docker network inspect app-netRunning Containers on It
Attach a container at start time with --network. Here we launch a Redis container that others will discover by name.
docker run -d --name cache --network app-net redis:7Name-Based Discovery
On a user-defined network the container name resolves via Docker DNS. An app simply connects to host cache on port 6379 instead of hunting for an IP.
docker run -it --network app-net alpine ping -c 2 cacheNetwork Aliases
Give a container an extra DNS name with --network-alias. Useful when several containers answer to one logical name behind a round-robin.
docker run -d --network app-net --network-alias db postgres:16Attaching a Running Container
You do not have to decide everything at launch. docker network connect attaches an already-running container to another network.
docker network connect app-net webDetaching from a Network
Symmetrically, docker network disconnect removes a container from a network without stopping it.
docker network disconnect app-net webExposing vs Publishing
Containers on the same custom network talk freely on any port. To reach a service from the host, publish a port with -p hostPort:containerPort.
docker run -d --network app-net -p 8080:80 nginxCleaning Up Networks
Remove an unused network with docker network rm, or prune every unused one at once. Networks with attached containers cannot be removed until those containers are gone.
docker network prune -fQuick Check
Test your understanding of service discovery.
Recap
You learned to create and manage custom bridge networks:
docker network createmakes an isolated network with DNS- Containers reach each other by name or
--network-alias connect/disconnectattach containers on the fly- Publish ports with
-p; prune unused networks
Service discovery by name is the foundation Compose builds on automatically.
Learn DevOps Bootcamp with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 142
- Lessons
- 568
Frequently Asked Questions
Is the “Custom Bridge Networks and Service Discovery” lesson free?
Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Custom Bridge Networks and Service Discovery”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.
What will I learn in “Custom Bridge Networks and Service Discovery”?
Create user-defined bridge networks so containers can find and talk to each other by name, and learn how Docker handles DNS-based service discovery. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.
How long does the “Custom Bridge Networks and Service Discovery” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Container Networking Basics
- Docker Volumes for Persistence
- Bind Mounts and tmpfs Mounts
- Custom Bridge Networks and Service Discovery