Home  Docker   Difference ...

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

  1. 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.
  2. 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.

Custom User-Defined Networks

  1. 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.
  2. 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

Example Scenario

  1. 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
    
  2. 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 and container4 are on different custom networks (mynetwork1 and mynetwork2) and are isolated from each other unless you establish connectivity between these networks explicitly.
Published on: Jul 01, 2024, 08:30 AM  
 

Comments

Add your comment