Demystifying Docker Networking: A Fundamental Overview

Welcome back, fellow Docker enthusiasts! In this enlightening lecture, we are diving headfirst into Docker Networking fundamentals. When it comes to Docker Networking, it all revolves around the Container Network Model (CNM) specifications. Docker, being the powerhouse it is, implements these CNM specifications through a framework known as libnetwork, which also offers the flexibility to integrate third-party drivers for more specific networking needs. Some notable drivers include Overlay, Bridge, and MACVLAN.

Now, let’s delve into the essential Docker networking concepts, starting with the default networks that come bundled with Docker. When you install Docker, you automatically inherit three primary networks: none, host, and bridge. Similar to volumes, you can also create your own custom networks, but today, we’ll focus on understanding these default options.

  1. None Network:
  • When you create a Docker container with the network set to “none,” the container doesn’t receive an IP address.
  • Containers isolated in the “none” network live in their little silo and are inaccessible from external systems.
  • You can still execute commands within these containers by referencing their container IDs.
  1. Host Network:
  • The “host” network uses the host driver.
  • Containers launched with the “host” network option become part of the host’s network namespace.
  • This means the container shares the host’s IP address, allowing you to access the container directly through the host’s IP.
  • Exposed ports in the Docker container are available on the host without requiring port mapping.
  1. Bridge Network:
  • When you use the “bridge” network, containers join a bridge network created by Docker, usually named “docker0.”
  • Each container in this network is assigned its unique IP address in the range of 172.17.0.x.
  • You can create custom bridge networks with different IP address ranges.
  • Containers in the same bridge network can communicate with each other.
  • To access services running in these containers from outside, you must map container ports to host ports.

In the case of the bridge network, each container gets an IP address in the range 172.17.0.x. These IPs can vary depending on the order in which containers are started and the bridge network’s subnet configuration.

In practice, mapping ports for containers on the bridge network is essential for access. For instance, if you launch a container with the command:

docker container run -d -p 8000:80 my_container

This command maps port 80 in the container to port 8000 on the host. To access a web page within the container, you would navigate to the host’s IP address followed by port 8000.

In the upcoming demo, we will showcase how to create Docker containers with different network types, specifically, we will use none, bridge, and host networks. We’ll dive into the containers, inspect the network interfaces, and demonstrate how to access web services within each container.

This fundamental knowledge of Docker networking will empower you to make informed decisions about how to connect your containers based on the specific requirements of your applications. Stay tuned for our enlightening demo in the next lecture!

Leave a Comment

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

Scroll to Top