Docker Networks

Docker Networks

Docker has revolutionized how we develop, ship, and deploy applications, and networking is a core part of this ecosystem. This article will cover what Docker networks are, the default networks Docker provides, and how you can create custom networks for seamless communication between your containers.

Default Docker Networks

When you install Docker, it comes with a set of predefined networks. These networks provide various levels of isolation and connectivity options:

  1. Bridge: The default network when you run a container. Containers within this network can communicate with each other using their IP addresses or container names. However, they are isolated from the host system and other networks.
  2. Host: This mode removes the isolation between the container and the Docker host. The container shares the host’s networking stack, meaning they will have the same IP address.
  3. None: Containers in this network are completely isolated and do not have any access to external networks or other containers.


Article content

Creating a Custom Docker Network

To create a custom network, we typically use the bridge driver, which is the most commonly used driver for Docker container communication. Here’s how you can create a custom network:

docker network create <network_name>        


Article content

Once created, you can inspect it using the following command to get details such as the network ID, subnet, and containers connected to it:

docker network inspect <network_name>        

You can now launch a container in this custom network:

docker run -dit --name container1 --network custom_network alpine        
docker run -dit --name container2 --network custom_network alpine        



Article content

Containers within this network can communicate using their names (DNS resolution is built in).

Facilitating Communication Between Two Custom Networks

To enable communication between containers on different custom networks, you can leverage Docker’s built-in routing capabilities or connect containers to multiple networks.

First, create two separate custom networks:

docker network create custom_net_1        
 docker network create custom_net_2        

Run containers on each network:

docker run -dit --name containerA --network custom_net_1 alpine 
docker run -dit --name containerB --network custom_net_2 alpine        

To allow containerA to communicate with containerB, you need to connect containerA to both networks:

docker network connect custom_net_2 containerA        

Now, containerA is part of both custom_net_1 and custom_net_2, and it can communicate with containers in both networks.


Docker networks play a crucial role in container communication and security. Understanding how to use default networks and create custom ones gives you the flexibility to design sophisticated microservices architectures. Whether it's isolating containers or ensuring smooth communication, Docker's networking features give developers powerful control over how their applications interact.

To view or add a comment, sign in

More articles by Vikas Mummidi

  • Docker Volumes

    Docker volumes are like special folders that Docker creates for containers to share easily and store data. They're like…

  • Virtual Machines and Containers

    Let’s explore the differences between virtual machines (VMs) and Docker containers. Both VMs and containers help…

Insights from the community

Others also viewed

Explore topics