Skip to content

Docker Cluster Management

This chapter covers Docker cluster management technologies, including Docker Swarm and Kubernetes basics.

Why Cluster Management?

Single-host Docker faces production challenges:

ProblemDescription
Single point of failureOne server down, all services unavailable
Resource bottleneckLimited single-machine resources
Load balancingNo automatic traffic distribution
Service discoveryDifficult cross-node communication

Docker Swarm

Docker Swarm is Docker's built-in cluster management and orchestration tool.

Architecture

┌─────────────────────────────────────────────┐
│              Docker Swarm Cluster            │
│                                             │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  │
│  │ Manager  │  │ Manager  │  │ Manager  │  │
│  │  Node 1  │  │  Node 2  │  │  Node 3  │  │
│  └────┬─────┘  └────┬─────┘  └────┬─────┘  │
│       │              │              │        │
│  ┌────▼─────┐  ┌────▼─────┐  ┌────▼─────┐  │
│  │ Worker   │  │ Worker   │  │ Worker   │  │
│  │  Node 1  │  │  Node 2  │  │  Node 3  │  │
│  └──────────┘  └──────────┘  └──────────┘  │
└─────────────────────────────────────────────┘

Initialize Swarm

bash
docker swarm init --advertise-addr <MANAGER-IP>
# Run the output join command on Worker nodes
docker node ls

Deploy Services

bash
docker service create --name web --replicas 3 -p 80:80 nginx:latest
docker service ls
docker service ps web
docker service scale web=5
docker service update --image nginx:1.25 web
docker service rm web

Deploy with Stack

yaml
# docker-stack.yml
version: '3.8'
services:
  web:
    image: nginx:latest
    deploy:
      replicas: 3
      update_config:
        parallelism: 1
        delay: 10s
      restart_policy:
        condition: on-failure
    ports:
      - "80:80"
bash
docker stack deploy -c docker-stack.yml myapp
docker stack ls
docker stack services myapp
docker stack rm myapp

Kubernetes Introduction

Kubernetes (K8s) is the most popular container orchestration platform.

Core Concepts

ConceptDescription
PodSmallest deployment unit, contains one or more containers
DeploymentManages Pod replicas and updates
ServiceProvides stable network access to Pods
NamespaceLogical resource isolation
ConfigMapConfiguration management
SecretSensitive information management

Try K8s with Docker Desktop

  1. Open Docker Desktop → Settings → Kubernetes
  2. Check "Enable Kubernetes"
  3. Click "Apply & Restart"
bash
kubectl cluster-info
kubectl get nodes

Basic Operations

bash
kubectl create deployment web --image=nginx --replicas=3
kubectl expose deployment web --port=80 --type=NodePort
kubectl get pods
kubectl get services
kubectl scale deployment web --replicas=5
kubectl set image deployment/web nginx=nginx:1.25
kubectl logs <pod-name>
kubectl delete deployment web

Docker Swarm vs Kubernetes

FeatureDocker SwarmKubernetes
Learning curveLowHigh
Setup complexitySimpleComplex
Feature richnessBasicVery rich
Community ecosystemSmallerVery large
ScaleSmall-mediumLarge
Docker integrationNativeRequires extra config
Auto-scalingManualSupported

Choosing

  • Docker Swarm: Small-medium teams, quick setup, simple cluster needs
  • Kubernetes: Large teams, complex microservices, rich ecosystem support needed

Chapter Summary

Cluster management is key to running containerized applications in production. Docker Swarm offers simplicity, while Kubernetes is the industry standard for large-scale orchestration. Choose based on team size and business requirements.

Further Reading

Content is for learning and research only.