Master Container Networking
Skill Path ( MediumHard )

This learning path will teach you how to reproduce the most typical container networking setup: the Docker(-like) bridge network. Virtual bridge networks are extremely widespread - most Docker and Podman installations and many Kubernetes clusters (via the corresponding CNI plugin) use them to provide inter-container (or pod) communication within a single host. Understanding the underlying concepts of the bridge network is the key to efficiently troubleshooting container and Kubernetes networking issues.

You'll start with the basics, like creating a network namespace, and then move on to more complex topics, like connecting multiple network namespaces with veth pairs and a bridge device and using iptables to set up network address translation (NAT) and port publishing.

Bridge Container Networking: step-by-step guide

Follow along with a comprehensive tutorial, or start by solving hands-on challenges and come back to the tutorial when you get stuck. Any way you choose, by the end of this skill path, you'll gain a deep understanding of how container networking works under the hood.

Theory: How Bridge Container Networks Work

Loading tutorial...

This rather massive tutorial contains a comprehensive explanation of how a Docker bridge network can be reproduced using common Linux command-line tools such as ip and iptables.

With a bottom-up approach, the tutorial starts with the basic concepts of Linux network namespaces and virtual Ethernet devices (veth pairs) and then moves on to illustrate the need for a "bridge" device to connect multiple network namespaces together and the involved routing and iptables rules.

It also covers the mechanisms of network address translation (NAT) and port forwarding, so the next time you run docker run -p 8080:80 nginx, you'll know what exactly is going on under the hood.

However, this tutorial might be too much to digest at once. So, if you feel that you're getting lost in the details, you can always start with solving the skill path's challenges and come back to the individual sections of this tutorial when/if you get stuck.

Practice: Create a Linux Network Namespace

Docker (and similar container runtimes) gives the containerized application the illusion of running in a dedicated network environment. This is achieved by using Linux network namespaces that provide a fully isolated set of network devices, IP protocol stacks, routing tables, firewall rules, etc., for each container.

Linux network namespace visualized.

We'll start the practice section of this learning path with a simple challenge where you'll need to create a new network namespace using basic Linux commands.

Practice: Connect Two Network Namespaces

Placing a container in its own network namespace to give the containerized application the illusion of a private network environment is a very powerful trick. However, such an isolation would be useless if it wasn't possible to communicate with the containerized apps.

Connecting network namespaces via veth device.

In this challenge, you'll need to connect a newly created network namespace with the host's (root) network namespace using a virtual Ethernet device:

Practice: Connect Multiple Network Namespaces

Connecting a new network namespace to the host's network namespace is relatively simple. However, containers rarely run in solitude. Most of the time, you'll find tens, if not hundreds, of containers running on a single server.

Route clash between two network namespaces.

In this follow-up challenge, you'll learn about the extra complexity that arises when you need to connect not two but multiple network namespaces together, and how to overcome the problem using a bridge device:

Practice: Set Up Network Address Translation (NAT) for a Container

Network devices connected to a single bridge network can communicate with each other on the link layer (L2). However, this doesn't suffice for containers to communicate with the outside world.

Container sNAT in action.

In this challenge, you'll learn how to set up network address translation (NAT) for a bridge network so that the containers can reach the outside world (e.g., the internet):

Practice: Forward a Port Without Starting a Proxy Process

Every container connected to a bridge network usually gets an IP address from the bridge network's subnet. Within the same bridge network, containers can communicate with each other using this IP address, and you can also access the container from the host via this IP address. However, such an IP address usually is not reachable from the outside world.

Container port publishing visualized.

The simplest way to expose a containerized application to the outside world is to "publish" the container's port to another port on one of the host's public interfaces. In this challenge, you'll learn how Docker (and similar container runtimes) implements it using a couple of iptables rules:

Practice: Reproduce a Docker Bridge Network Using Basic Linux Commands

At this point, you should have a good understanding of all the moving parts involved in creating a Docker bridge network. The only thing left to do is to put all the pieces together and reproduce the Docker bridge network from scratch.

Docker bridge network visualized.

To prove your container networking mastery, solve this ultimate challenge:

Good luck!

Level up your Server Side game — Join 9,500 engineers who receive insightful learning materials straight to their inbox