Abdullah Fathi
Pautan Muat Turun
Containers Everywhere = New Problem
Docker Swarm to The Rescue
Rolling Updates
Scaling & Load Balancing
Secure by Default
Manager Node
Worker Node
Create n-Node Swarm
Initialize Docker Swarm
# Check if swarm has been enabled or not
docker info
# Initialize docker swarm
docker swarm init --advertise-addr <ip-addr>
Add Node to the Cluster
# View node list
docker node ls
# Add worker node to the cluster
docker swarm join --token ...
# Promote worker node to manager
docker node update --role manager node2
# Create docker swarm join command for manager
docker swarm join-token manager
Swarm Basic Features
# Create overlay network
docker network create --driver overlay mydrupal
# Create Postgres Service
docker service create --name psql --network mydrupal -e POSTGRES_PASSWORD=mypass postgres:14
# Create Drupal Service
docker service create --name drupal --network mydrupal -p 8822:80 drupal:9
Overlay Multi-Host Networking
Swarm Basic Features
# Create elasticsearch service
docker service create --name search --replicas 2 -p 9200:9200 elasticsearch:2
Routing Mesh
You can use any node that is participating in the swarm, even if there is no replica of the service in question exists on that node. So you will use Node:HostPort
combination. The ingress routing mesh will route the request to an active container
The advantage of using a proxy (HAProxy) in-front of docker swarm is, swarm nodes can reside on a private network that is accessible to the proxy server, but that is not publicly accessible. This will make your cluster secure
Stacks: Production Grade Compose
Sample Application
Stacks: Production Grade Compose
Using Secret in Swarm Services
Stacks: Production Grade Compose
Using Secret in Swarm Services (cont..)
Stacks: Production Grade Compose
Service updates
docker container ls
Stacks: Production Grade Compose
Docker Healthchecks
Stacks: Production Grade Compose
Docker Healthchecks (Cont...)
Healthchecks (Docker Run Example)
docker run \
--health-cmd="curl -f localhost:9200/_cluster/health || false" \
--health-interval=5s \
--health-retries=3 \
--health-timeout=2s \
--health-start-period=15s \
elasticsearch:2
Healthchecks (Dockerfile Example)
--interval=DURATION (default: 30s)
--timeout=DURATION (default: 30s)
--start-period=DURATION (default: 0s) (17.09+)
--retries=N (default: 3)
HEALTHCHECK curl -f http://localhost/ || false
HEALTHCHECK --timeout=2s --interval=3s --retries=3 \
CMD curl -f http://localhost/ || exit 1
Healthchecks (Compose / Stack File)
version: "3.9"
services:
web:
image: nginx
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 1m
Explore/Misc
Your feedback matters
There are no secrets to success. It is the result of preparation, hard work, and learning from failure. - Colin Powell