Docker Network Configuration
Create and manage Docker networks for container-to-container communication and service isolation.
# Create custom bridge network
docker network create --driver bridge app-network
# Create network with specific subnet
docker network create \
--driver bridge \
--subnet 172.20.0.0/16 \
--gateway 172.20.0.1 \
app-network
# Run containers on the same network
docker run -d --name api --network app-network myapp:latest
docker run -d --name db --network app-network postgres:16
# Containers can now resolve each other by name:
# From api container: postgres://db:5432/mydb
# Connect existing container to a network
docker network connect app-network existing-container
# Disconnect from a network
docker network disconnect bridge existing-container
# Inspect network details
docker network inspect app-network
# List all networks
docker network ls
# Remove unused networks
docker network prune
# docker-compose.yml with multiple networks
# services:
# api:
# networks: [frontend, backend]
# db:
# networks: [backend]
# nginx:
# networks: [frontend]
# networks:
# frontend:
# backend:
# internal: true # no external accessUse Cases
- Isolating database containers from public access
- Microservice communication within Docker
- Multi-tier application network architecture
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Docker Compose Multi-Service Setup
Docker Compose configuration for a Node.js app with PostgreSQL, Redis, and Nginx reverse proxy.
Best for: Local development environment with multiple services
Docker Health Check Patterns
Docker health check configurations for web apps, databases, and message queues with restart policies.
Best for: Ensuring container readiness before traffic routing
Kubernetes Deployment Configuration
Production-ready Kubernetes deployment with replicas, resource limits, health checks, and rolling updates.
Best for: Production container orchestration
Redis Docker Setup with Persistence
Docker Compose for Redis with persistence, password auth, memory limits, and a health check.
Best for: Local Redis instance for development