Docker Networking, Storage & Volumes (The Masterclass Manual)

An analogy-driven, professional-grade guide to Docker networking drivers (Bridge, Host, Overlay), iptables NAT port forwarding, storage persistency mechanisms, Named Volumes, and Bind Mounts.

High-Level Concept Definition & Real-World Analogy

Docker Networking and Storage Subsystems manage how containers communicate across network interfaces and persist data beyond container process lifecycles.

Core Architectural Features

  • Isolated Virtual Networks: Provides bridge (docker0), host, overlay, and macvlan network drivers to isolate container traffic.
  • iptables NAT Routing: Maps host external network interfaces to internal private container IP addresses via Network Address Translation (NAT).
  • Decoupled Persistency: Decouples stateful storage from ephemeral container layers using managed Named Volumes, Bind Mounts, or tmpfs mounts.

Real-World Analogy: The Gated Apartment Complex Utility Grid

To visualize container networking and storage mechanics, consider a Gated Apartment Complex Utility Grid:

  • Bridge Network (bridge): An Internal Gated Complex Intercom Network. Every apartment (container) gets a private internal extension number (172.17.0.X). Apartments talk to each other freely, but outsiders must go through the main gate receptionist.
  • Port Forwarding (-p 8080:80): The Front Gate Reception Switchboard. When a caller outside dials main complex line 8080, the gate switchboard routes the call directly to internal extension 80 in Apartment 4.
  • Host Network (host): Eliminating the Receptionist. Apartment 4 plugs its telephone line directly into the city street pole, bypassing internal complex routing entirely (zero NAT latency, but port conflicts possible!).
  • Ephemeral Container Storage: Temporary Apartment Chalkboard. Any notes written on the living room wall disappear the instant the lease ends (docker rm).
  • Named Volume (-v my-db-data:/var/lib/mysql): A Managed Secure Storage Locker located in the apartment basement. If the apartment tenant moves out or is evicted, the basement locker remains locked and intact for the next tenant.
  • Bind Mount (-v /host/path:/container/path): A Direct Pipeline Window opened between a specific room in your personal house and a room inside the apartment.
Host OS Network & Storage Layer iptables NAT Forwarding Virtual Eth Pair (veth) Virtual Eth Pair (veth) Bypasses OverlayFS External Client Traffic(http://host-ip:8080) Docker Bridge Network (docker0)(Subnet: 172.17.0.0/16) Container 1 (Web App)(IP: 172.17.0.2:80) Container 2 (Database)(IP: 172.17.0.3:5432) Docker Named Volume(/var/lib/docker/volumes/db_data/_data)

Structured Module Roadmap

ModuleCore TopicsKey Focus & Engineering ConceptsRead Time
Docker Network DriversBridge, Host, None, Overlay, MacvlanDriver Architecture, Multi-Host Swarm Networks, Network Isolation5 min
Port Forwarding & NAT-p 8080:80, iptables, docker0Port Translation, Network Address Translation, Socket Latency4 min
Storage Persistency MechanicsNamed Volumes vs. Bind Mounts vs. tmpfsHost Bypass, Volume Drivers, In-Memory Ephemeral Storage4 min
Permissions & LifecycleVolume Drivers, UID/GID Mapping, chownNon-Root Volume Access, Host Path Mounting Risks4 min

Quick Reference & Comparison Matrices

1. Docker Network Drivers Architecture Matrix

Network DriverIP Allocation SchemeNetwork Isolation LevelPerformance OverheadPrimary Enterprise Use Case
Bridge (bridge) (Default)Internal Subnet (172.17.0.X)High (Private virtual bridge per network)Low (iptables NAT translation)Standard multi-container apps on a single host.
Host (host)Shares Host IP & Port SpaceNone (Uses host network stack directly)Zero (Native performance)High-throughput streaming, latency-critical apps.
Overlay (overlay)VXLAN Subnet across hostsHigh (Encapsulated multi-host overlay)Moderate (VXLAN encapsulation)Docker Swarm & Multi-Node Cluster Orchestration.
None (none)No IP assigned (Loopback only)Complete (100% Network Air-Gap)N/AHigh-security offline batch processing, crypto tasks.
MacvlanAssigns MAC address from physical LANDirect Physical LAN IntegrationLow (Direct routing)Legacy apps requiring direct physical IP addresses.

2. Storage Persistency Types Taxonomy

Storage TypeHost LocationManaged by Docker?Persists After docker rm?Primary Production Use Case
Named Volume/var/lib/docker/volumes/<name>/_dataYes (Controlled via docker volume)Yes (Permanent until explicit removal)Databases (PostgreSQL, MySQL), Stateful App Data.
Bind MountUser-defined path (e.g. /home/user/app)No (Direct host directory mapping)Yes (Managed by host filesystem)Local development code hot-reloading.
tmpfs MountHost System Memory (RAM)Yes (Memory-backed mount)No (Erased on container stop)Sensitive keys, passwords, high-speed temp buffers.

CLI Command Masterclass: Network & Volume Operations

1. docker network Management CLI

  • Mental Model: Creates and manages isolated virtual bridge networks and attaches containers dynamically to embedded DNS zones.
Command & SubcommandOperational Purpose
docker network create app-netCreates a custom user-defined bridge network with automatic embedded DNS service discovery.
docker network lsLists all active local network drivers (bridge, host, none, custom).
docker network connect app-net container1Dynamically attaches a running container to a second network without restarting.
docker network inspect app-netDisplays active subnet range, gateway IP, and attached container list with assigned IPs.
# Network Management Pipeline
$ docker network create --driver bridge backend-net
$ docker network connect backend-net my-api

2. docker volume Management CLI

  • Mental Model: Manages persistent storage lockers under /var/lib/docker/volumes/ that bypass the container's OverlayFS layer.
# 1. Create Managed Named Volume
$ docker volume create db_store

# 2. Inspect Host Physical Mountpoint Path
$ docker volume inspect db_store --format '{{ .Mountpoint }}'

# 3. Purge all unattached unused storage volumes
$ docker volume prune -f

Architectural Deep-Dive & Engineering Concepts

1. How Port Forwarding Works via iptables NAT

When you launch a container with -p 8080:80, Docker manipulates host iptables rules:

# Inspecting Docker NAT Rules in Host iptables
$ sudo iptables -t nat -L DOCKER -n -v

Interactive Self-Assessment Checkpoints

Knowledge Check

Why is DNS automatic container name resolution (e.g. pinging 'db' by name) supported on custom user-defined bridge networks but NOT on the default 'bridge' network?

Knowledge Check

What happens to data stored inside a Named Volume (-v my-data:/app/data) when the container attached to it is deleted with docker rm -f?

Knowledge Check

What performance trade-off occurs when using host network mode (--network host) instead of standard bridge network mode?

Problem: Setting Up Persistent PostgreSQL Container with Healthcheck and Named Volume

Write a shell script to create a user-defined Docker bridge network app-net, create a managed Named Volume db-store, and deploy a PostgreSQL 16 container with persistent storage and port forwarding.

On this page