Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 76 of 8021. Container FundamentalsFree lesson

Managing User-Defined Bridge Networks

Create custom bridge networks to enable automatic DNS resolution and service discovery between containers using their assigned container names.

In this lesson, you will learn how to create custom bridge networks to enable automatic DNS resolution, allowing your containers to communicate seamlessly using their names instead of unreliable IP addresses.

Why the Default Bridge is Not Enough

When you run containers without specifying a network, they attach to the bridge network (the default). While containers here can communicate, they are limited: they usually have to rely on IP addresses to find one another. If a container restarts and gets a new IP, your application breaks. Furthermore, the default bridge does not support automatic service discovery by name.

Creating a User-Defined Bridge

A user-defined bridge network acts like a private virtual switch for your containers. When you create one, Docker automatically provides a built-in DNS server for that network. This allows any container connected to it to "resolve" the name of another container to its internal IP address.

First, create your network:

docker network create my-app-network

Next, run two containers and attach them to this specific network:

docker run -d --name database --network my-app-network redis
docker run -d --name web-app --network my-app-network nginx

Automatic Service Discovery

Because both containers are on my-app-network, your web-app container can now reach the database simply by using its name. You don’t need to know the database's IP address. From inside the web-app container, you can perform a command like ping database, and Docker’s internal DNS will map that name directly to the correct container.

This approach is much more robust than the default bridge because it decouples your application logic from the underlying network configuration. If you stop, remove, and recreate the database container, the new instance will simply register its name with the network’s DNS, and your web-app will find it instantly without any code changes.

Key Takeaway: User-defined bridge networks provide an internal DNS service that allows containers to talk to each other using simple, human-readable names instead of fragile IP addresses.