Networking in Docker

Reading Time: 4 minutes

Networking is about communication among processes, and Docker’s networking is no different. A docker network is basically a connection between one or more containers. It is very easy to isolate and manage the containers, as different containers can be easily connected to each other.

Docker supports different types of networks, each fit for certain use cases. Let’s take a look at each one:

Bridge Network:

This is the default network created by docker on the host machine on which it is installed. Docker containers that are connected by the means of a bridge network can communicate with each other. So, containers connected to this network communicate via IP addressing. 

 Creating a bridge network run the below command:

To list all the networks run the below command:

To remove a specific network run the below command:

For getting a detailed information about the network run the below command:

Create a container connected with the my-bridge network:

Host Networking:

Host networking is used for standalone containers. Docker containers that are connected to the host network basically share the namespaces with their hosts. In other words the container shares the IP address of the host and doesn’t have one of its own.

The following command will start an Nginx image and connect to the host network:

And when you will inspect it will show no ip address:

Overlay Network:

The Overlay network driver is used to create an internal private network. It is used when the containers can communicate with each other securely even when the containers are running on different hosts and are on different containers. This is useful when we need a set of docker hosts to communicate with each other in a docker swarm.

For instance let’s set up a network connecting three containers on three different docker hosts. Firstly create two EC2 instances (free tier should be fine), and install Docker on each EC2 instance.

  1. Create a swarm on host1 and host1 becomes your manager node.
  1. After that, Copy the token and paste it in host2 this will become your worker node.
  1. On host1, verify that the swarm is ready:
  1. On host1, verify the default networks:
  1. Overlay Network Creation on Node 1
  1. Run Our Container, Join the Overlay Net on host1
  1. Run Our Container, Join the Overlay Net on host2
  1. From Node 1, let’s ping the Node 2 container.
  1. From Node 2, let’s ping the Node 1 container.

Therefore, your connection has been successfully established.

None Network:

A docker network which has none network configured for itself cannot communicate with any service or system as networking for the container is virtually disabled. It is usually used to isolate containers.

Creating a none network:


In conclusion You came to know about Networking in Docker. You now know that Docker networking is primarily used to establish communication between Docker containers and the outside world via the host machine where the Docker daemon is running. Docker supports different types of networks, each fit for certain use cases.

Written by 

Naincy is currently a Software Intern at Knoldus. She is always ready to learn new technologies and tools. She loves painting and dancing.