How docker networking works.

In recent articles, we talked about containers a lot like the below articles. In this article also we are going to continue the same trend and talk about how docker networking works.

To understand very basic docker networking we need some knowledge beforehand. Lets read about namespaces in linux, veth pair and bridge.

Namespaces:

Namespaces are a feature of the kernel which allows the partitioning of the system resources. One such resource is networking. Our network is there is default namespaces. We cannot see that because the whole OS uses the same namespaces.

Veth Pair:

It’s just like a link cable. Whatever you send on one end of the pair will be received at the other end.

Bridge:

Bridge generally sits in between two computers and based on the destination of the packet decides where to forward the packet to. You can consider bridges as switch.

Now, let’s start with Docker networking.

Docker Networking

Whenever a new docker container comes up it has a veth pair by default. Now there are following namespaces that are present.

Network namespace for default network interface and container namespace for container.

One end of veth pair of the container reside in bridge and the other one resides in the container network namespace. Similarly, the other veth pair is between the bridge and network namespace.

Thus anything coming to network namespace destined to containers will be passed to bridge using the veth pair and bridge will forward the packet the corresponding veth pair depending on the destination. The other end of veth pair can receive packet that is a container.

This article was just about how bridge network works with containers. We will talk about other way in later posts.

Till then subscribe and stay updated. Join our facebook group or linkedin group for more updates.


Gaurav Yadav

Gaurav is cloud infrastructure engineer and a full stack web developer and blogger. Sportsperson by heart and loves football. Scale is something he loves to work for and always keen to learn new tech. Experienced with CI/CD, distributed cloud infrastructure, build systems and lot of SRE Stuff.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.