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 Docker & DevOps Fundamentals lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Docker & DevOps Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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.
Frequently asked questions
Is the “Custom Bridge Networks and Service Discovery” lesson free?
Yes — the full text of “Custom Bridge Networks and Service Discovery” is free to read here on the web, and the Docker & DevOps Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Docker & DevOps Fundamentals course, upgrade to CoddyKit PRO.
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 Docker & DevOps Fundamentals 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 Docker & DevOps Fundamentals?
No prior experience is required. Docker & DevOps Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
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 Docker & DevOps Fundamentals lesson?
Yes. Every Docker & DevOps Fundamentals 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