Agentic AI with Java: Live Cohort
DockerDocker Networking

Docker Custom Bridge Networks

Create custom bridge networks so containers can communicate by name in a cleaner way.

Custom bridge networks are one of the most useful Docker networking features for beginners.

They let related containers communicate with each other by container name. This makes multi-container setups cleaner than using the default bridge network.

Create a custom network

docker network create app-network

Check it:

docker network ls

Run containers on the network

Start a database container:

docker run -d --name database --network app-network mysql:8

Start an app container on the same network:

docker run -d --name api --network app-network my-api:1.0

Now api can reach the database using the hostname:

database

Docker provides name resolution inside the custom network.

Why custom networks are better

Custom bridge networks are better for app setups because:

  • Containers can find each other by name
  • Related containers are grouped together
  • Network setup is easier to inspect
  • You avoid hard-coding container IP addresses
  • It feels closer to Docker Compose and production-style setups

Inspect a network

docker network inspect app-network

This shows containers connected to the network and their assigned IP addresses.

Connect an existing container

You can connect a running container to a network:

docker network connect app-network container-name

And disconnect it:

docker network disconnect app-network container-name

Remove a network

After removing containers, remove the network:

docker network rm app-network

Docker will not remove a network if containers are still attached.

Simple mental model

Use a custom bridge network when containers belong to the same application.

app-network
-> api container
-> database container
-> cache container

For multi-container practice, create a custom bridge network and use container names instead of IP addresses.

How is this guide?

Last updated on