Difference between Docker's default bridge network and Custom network
Let us see the difference between Docker's default bridge network and Custom networks:
Default Bridge Network
-
Single Default Bridge Network:
- Docker creates a single default bridge network named
bridge
when you install Docker. - All containers that you run without explicitly specifying a custom network are attached to this default bridge network.
- Docker creates a single default bridge network named
-
Isolation Within Default Bridge:
- Containers attached to the default
bridge
network can communicate with each other using IP addresses assigned by Docker. - Each container on the default bridge network gets its own unique IP address within the subnet of the
bridge
network. - By default, containers on the same
bridge
network can communicate with each other.
- Containers attached to the default
Custom User-Defined Networks
-
Creating Custom Networks:
- Docker allows you to create multiple custom user-defined networks using the
docker network create
command. - Each custom network you create is separate and isolated from other networks unless you explicitly connect containers between them.
- Docker allows you to create multiple custom user-defined networks using the
-
Isolation Between Custom Networks:
- Containers connected to different custom networks are isolated from each other by default. They cannot communicate directly unless you explicitly connect them using Docker’s network features.
Clarification
-
Default Bridge Network: There is indeed only one default bridge network (
bridge
) created by Docker. All containers not explicitly attached to a custom network are part of this default bridge network. -
Custom Networks: You can create multiple custom networks (
mynetwork1
,mynetwork2
, etc.) using Docker’s network management features. Each custom network provides isolation between containers unless you configure network connectivity between them.
Example Scenario
-
Single Default Bridge Network:
- If you run two containers without specifying a custom network, both containers will be part of the default
bridge
network. - They can communicate with each other using their container names or IP addresses assigned by Docker.
docker run -d --name container1 nginx docker run -d --name container2 nginx
- If you run two containers without specifying a custom network, both containers will be part of the default
-
Multiple Custom Networks:
- You can create separate custom networks and attach containers to them to achieve network isolation.
docker network create mynetwork1 docker network create mynetwork2 docker run -d --name container3 --network mynetwork1 nginx docker run -d --name container4 --network mynetwork2 nginx
container3
andcontainer4
are on different custom networks (mynetwork1
andmynetwork2
) and are isolated from each other unless you establish connectivity between these networks explicitly.
Published on: Jul 01, 2024, 08:30 AM