7.1.2.2 User Defined Networks
A focused guide to User Defined Networks, connecting core concepts with practical Docker and container operations.
User-defined networks are Docker networks explicitly created by name, distinct from the automatically provided default bridge network, offering better isolation, automatic name-based DNS resolution, and generally more deliberate, controllable networking behavior for multi-container applications.
Creating a User-Defined Network
A new network is created explicitly, given a name that containers can later reference when they connect to it.
docker network create app-network
Attaching Containers to a User-Defined Network
Containers explicitly join a user-defined network at creation time, or can be connected to it afterward.
docker run -d --name api --network app-network myapi:1.0
docker network connect app-network another-container
Why User-Defined Networks Are Generally Preferred Over the Default Bridge
Beyond automatic DNS-based name resolution (which the default bridge lacks), user-defined networks provide better isolation between unrelated groups of containers, since containers not explicitly attached to a given user-defined network cannot communicate with containers that are.
docker network create frontend-net
docker network create backend-net
Separating distinct application tiers onto their own dedicated networks limits unintended cross-communication between unrelated parts of a larger system.
Customizing a User-Defined Network's Configuration
A user-defined network's address range, gateway, and other settings can be explicitly configured at creation time, rather than relying on Docker's automatic defaults.
docker network create --subnet=172.25.0.0/16 --gateway=172.25.0.1 custom-net
Listing and Inspecting Existing Networks
Currently defined networks, and which containers are attached to each, can be reviewed directly.
docker network ls
docker network inspect app-network
Why User-Defined Networks Matter
Adopting user-defined networks as the standard approach for multi-container applications provides meaningfully better name resolution, isolation, and configurability than relying on the default bridge network, making them the generally recommended choice for any application involving more than a single, standalone container.