0Pricing
Docker & DevOps Fundamentals · Lesson

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 ls

Creating 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-net

Inspecting the Network

docker network inspect shows the subnet, gateway, and any attached containers as JSON. Handy for debugging IP ranges.

docker network inspect app-net

Running 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:7

Name-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 cache

Network 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:16

Attaching 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 web

Detaching from a Network

Symmetrically, docker network disconnect removes a container from a network without stopping it.

docker network disconnect app-net web

Exposing 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 nginx

Cleaning 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 -f

Quick Check

Test your understanding of service discovery.

Recap

You learned to create and manage custom bridge networks:

  • docker network create makes an isolated network with DNS
  • Containers reach each other by name or --network-alias
  • connect/disconnect attach 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

  1. Container Networking Basics
  2. Docker Volumes for Persistence
  3. Bind Mounts and tmpfs Mounts
  4. Custom Bridge Networks and Service Discovery
← Back to Docker & DevOps Fundamentals