🐳

Docker Networking Lecture Notes

Jul 23, 2024

Docker Networking Lecture Notes

Introduction

  • Docker Containers: Lightweight, fast, and widely used.
  • Networking Mystery: Understanding how Docker networking works is crucial.
  • Different Network Types: There are seven different network types in Docker.
  • Objective: Explore the different Docker network types and their functions.

Requirements

  • Prerequisites: Basic knowledge of Docker containers.
  • Host Setup: A Linux virtual machine (VM) with Docker installed. Example used is Ubuntu Desktop on VirtualBox.
  • Network Configuration: Use bridge adapter in VM settings to connect directly to the home network.

Default Bridge Network

  • Installation: Install Docker on the Ubuntu VM.
  • Check Interfaces: Before Docker install, ip addr show shows loopback and main network interface. Post-install, Docker adds docker0 virtual bridge interface.
  • Docker Commands: docker network ls lists networks, docker run launches containers, docker network inspect bridge inspects networks.
  • Deploying Containers: Use docker run -dit --rm --name <name> <image> to deploy containers. Containers get virtual interfaces connected to docker0 bridge.
  • Interaction: Containers can communicate through their bridged network interfaces.
  • Port Exposure: Manually expose ports using -p option while deploying containers to access services from the host network.

User-Defined Bridge Network

  • Creation: Create using docker network create <name>.
  • Benefits: Better isolation and built-in DNS for container communication.
  • Commands: Use docker run --network <network_name> to deploy containers to this network.
  • Container Communication: Containers in user-defined networks can communicate by name due to DNS.

Host Network

  • Function: Containers share the host’s network stack.
  • Deployment: Use --network host without port exposure.
  • Scenario: Good for deploying VPN services where container needs direct host network access.

MacVLAN Network

  • Concept: Connects containers directly to the physical network.
  • Setup: Use docker network create -d macvlan --subnet=<subnet> --gateway=<gateway> -o parent=<interface>.
  • Advantages: Containers get unique MAC addresses and can directly access the home network.
  • Challenges: Requires promiscuous mode enabled on the switch port; no DHCP, static IP assignment required.

IPvlan Network

  • Modes: L2 (Layer 2) and L3 (Layer 3).
  • L2 Mode: Similar to MacVLAN but shares the host’s MAC address instead of having unique ones.
  • L3 Mode: Focuses on IP routing, making host a router for containers. Uses static routes to connect networks.
  • Command: Use --ipvlan-l3 options for creating an L3 network.

Overlay Network

  • Usage: For multi-host Docker Swarm setups, interconnects containers across different hosts.
  • Scenario: Ideal for large-scale applications with multiple Docker hosts.

None Network

  • Feature: Provides total network isolation.
  • Deployment: Use --network none to create containers with no network access, only loopback interface.
  • Usage: For maximum isolation and security.

Conclusion

  • Networking Skills: Docker networking is a vital skill for modern container-based applications.
  • Application: Experiment with different networks in a lab setup and include the experience on your resume.
  • Favorite Networks: Highlight favorites like MacVLAN and IPvlan for their advanced networking capabilities.
  • Engagement: Encouraged to explore further and interact with each network type.

Additional Sections

  • Sponsor: BitDefender – for cybersecurity solutions.
  • Call to Action: Engage with the content, comment, like, and subscribe for more tech-related videos.