Docker Compose Networks
Published on: September 24, 2025
Tags: #docker-compose #network
Docker Compose Default Network
graph LR subgraph "Project: myapp" subgraph "Default Bridge Network
(myapp_default)" web[Service: web] api[Service: api] db[Service: db] end end web <--> api api <--> db web <--> db style web fill:#f9f,stroke:#333,stroke-width:2px style api fill:#9cf,stroke:#333,stroke-width:2px style db fill:#ccf,stroke:#333,stroke-width:2px
Custom Networks for Segmentation
graph TD subgraph "Application" subgraph "Frontend Network" web[Service: web] end subgraph "Backend Network" db[Service: db] end %% Define the shared API service outside the network subgraphs api[Service: api] %% Define the connections web <--> api api <--> db end %% Apply styles to match the original image style web fill:#f9f,stroke:#333,stroke-width:2px style db fill:#ccf,stroke:#333,stroke-width:2px style api fill:#9cf,stroke:#333,stroke-width:2px
Service Discovery via Docker's DNS
sequenceDiagram participant web as Service A (web) participant dns as Docker DNS Resolver participant db as Service B (db) web->>dns: Who is the service 'db'? (DNS Query) activate dns %% Changed to a dashed arrow for a reply message dns-->>web: The service 'db' is at IP 172.18.0.5 deactivate dns web->>db: Connect to 172.18.0.5 activate db db-->>web: Connection established deactivate db
Overview of Docker Network Drivers
graph TD A[Docker Network Drivers] --> B[Single-Host]; A --> C[Multi-Host]; B --> B1["bridge (default)
Creates a private, isolated
network on the host"]; B --> B2["host
Removes network isolation,
shares host's network"]; B --> B3["macvlan
Assigns a MAC address,
container appears as a
physical device"]; B --> B4["none
Disables all networking for
a container"]; C --> C1["overlay
Creates a distributed
network spanning multiple
hosts (for Swarm)"];