Docker network types with focus on Bridged networks
How to create and handle networks with Docker? We will create bridge networks, and use them with our containers.
Last time we talked about networking with Docker Compose. Compose did the heavy lifting for us in the background, so it may not be apparent what exactly had to be configured for the two containers to be able to communicate with each other. This time we will take a closer look at the networking capabilities of Docker. There’s even more to Docker Compose and its networking, but today our focus is on plain Docker, so we can learn the basics first.
In this article we will be creating custom bridge networks, see how we can utilize them with our containers, and how to make them configurable on the operating system level.
Before we begin, a word from our friends
Do you enjoy getting exposed to new ideas outside your usual bubble? Me too. The Sample was designed to amplify independent writers who you haven't heard of already. You can set a few topics you're interested in, and then each day The Sample picks a different article to send you. When you get one you like, you can subscribe to the author's newsletter in a single click. Easy as pie. Sign up here.
What are Docker networks?
As we already discussed in the previous post Docker Compose networking, we can list currently existing networks with the following command:
docker network ls
This outputs for example:
NETWORK ID NAME DRIVER SCOPE
56a19d16e12f bridge bridge local
a26d7826640e host host local
7e93d3c8fbc2 none null local
There’s three networks by default. But what are they, and why do they exists? What are the different types of network drivers we see on the list? Are there more than just those three? Let’s take a look.
The following are all the possible driver types Docker currently supports:
Bridge - This is the default network type. When you create a network without specifying a type, you are creating a Bridge type network. Bridge networks are used to connect containers running on the same docker engine. Most common use case is to connect multiple containers on the same Bridge network, so they can communicate with each other on the same host. Containers connected to Bridge networks are not exposed to host machine’s network, unless ports are published by command.