Introduction To Docker - PACKT Books: Rajdeep Dua, The Author of The Book Learning Docker
Introduction To Docker - PACKT Books: Rajdeep Dua, The Author of The Book Learning Docker
In this article by Rajdeep Dua, the author of the book Learning Docker
Networking, we will look at an introduction of Docker networking and its
components.
Each Docker container has its own network stack, and this is due to the Linux
kernels net namespace, where a new net namespace for each container is
instantiated and cannot be seen from outside the container or from other
containers.
Linux bridges
These are L2/MAC learning switches built into the kernel and are to be used for
forwarding.
Open vSwitch
NAT
1
IPtables
This is a policy engine in the kernel used for managing packet forwarding,
firewall, and NAT features.
AppArmor/SELinux
Various networking components can be used to work with Docker, providing new
ways to access and use Docker-based services. As a result, we see a lot of
libraries that follow a different approach to networking. Some of the prominent
ones are Docker Compose, Weave, Kubernetes, Pipework, and Libnetwork. The
following figure depicts the root ideas of Docker networking:
Docker networking is at a very nascent stage, and there are many interesting
contributions from the developer community, such as Pipework, Weave, Clocker,
and Kubernetes. Each of them reflects a different aspect of Docker networking.
We will learn about them in later chapters. Docker, Inc. has also established a
new project, where networking will be standardized. It is called libnetwork.
2
Libnetwork implements the Container Network Model (CNM), which formalizes
the steps required to provide networking for containers while providing an
abstraction that can be used to support multiple network drivers. The CNM is
built on three main componentssandbox, endpoint, and network.
Sandbox
Endpoint
Network
A network is a group of endpoints that are able to communicate with each other
directly. An implementation of a network could be a Linux bridge, a VLAN, and so
on. Networks consist of many endpoints, as shown in the following diagram:
3
The Docker CNM model
The CNM provides the following contract between networks and containers:
All containers on the same network can communicate freely with each other
Multiple networks are the way to segment traffic between containers and
should be supported by all drivers
Multiple endpoints per container are the way to join a container to multiple
networks
An endpoint is added to a network sandbox to provide it with network
connectivity