Introduction to Docker Networking
Learn how to understand Docker networking, including the Container Network Model, and libnetwork.
We'll cover the following
It’s always the network!
Any time we experience infrastructure issues, we always blame the network. One reason is that networks are at the center of everything. With this in mind, it’s important that you have a strong understanding of Docker networking. Networking was difficult in the early days of Docker. Fortunately, it’s almost a pleasure these days.
This chapter will help you understand the fundamentals of Docker networking. You’ll learn the theory behind the Container Network Model (CNM) and libnetwork, and get hands-on with plenty of examples. You’ll learn about overlay networks in the next chapter.
Prerequisites and environment setup
A few quick things before we start: Everything we’ll cover relates to Linux containers. We recommend you follow along using something like Multipass or Play with Docker, as they give you easy access to some of the Linux commands we’ll use. We don’t recommend following along on Docker Desktop, as it runs everything inside a Linux VM, and you won’t have access to the Linux commands.
Some of the examples explain how networking works on a swarm. You’ll only be able to follow these if you’re following along with a Swarm cluster.
The TLDR
Docker runs microservices applications comprised of many containers that work together to form the overall app. These containers need to be able to communicate, and some will have to connect with external services, such as physical servers, virtual machines, or something else.
Fortunately, Docker has solutions for both of these requirements.
Docker networking is based on libnetwork, which is the reference implementation of an open-source architecture called the Container Network Model (CNM). For a smooth, out-of-the-box experience, Docker ships with everything you need for the most common networking requirements, including multi-host container-to-container networks and options for plugging into existing VLANs. However, the model is pluggable, and the ecosystem can extend Docker’s networking capabilities via drivers that plug into libnetwork. Last but not least, libnetwork also provides native service discovery and basic load balancing.
That’s the big picture. Let’s get into the detail.
Get hands-on with 1400+ tech skills courses.