Docker Swarm turns multiple VPS instances into a single, coordinated container cluster — distributing services across nodes, restarting failed containers automatically, and enabling zero-downtime rolling deployments. For Asia-Pacific applications that need more resilience than a single VPS provides, a Docker Swarm cluster across two or three Hong Kong VPS instances delivers high availability with CN2 GIA routing on every node.
When to Use Docker Swarm vs Single VPS
| Scenario | Single VPS | Docker Swarm |
|---|---|---|
| Development / staging | ✓ Simpler | Overkill |
| Production, 99.9% uptime required | SPOF risk | ✓ Multi-node HA |
| Horizontal scaling needed | Scale up only | ✓ Scale out |
| Rolling zero-downtime deploys | Possible but manual | ✓ Native support |
| Budget under $30/month | ✓ More cost-effective | Needs 2+ VPS |
Architecture: 3-Node Swarm
[Manager Node — HK VPS 1] 10.0.0.1
|
[Swarm Overlay Network — 10.0.10.0/24]
|
[Worker Node 1 — HK VPS 2] 10.0.0.2
[Worker Node 2 — HK VPS 3] 10.0.0.3
Three nodes gives you one manager and two workers, with fault tolerance for one node failure. For production, use three manager nodes (quorum requires majority to elect a leader) — but for most applications, one manager and two workers is sufficient.
Step 1: Prepare All Nodes
Run on all three VPS instances:
# Install Docker on each node
curl -fsSL https://get.docker.com | sh
systemctl enable --now docker
# Configure firewall — allow Swarm communication
ufw allow 22/tcp # SSH
ufw allow 2377/tcp # Swarm management
ufw allow 7946/tcp # Node communication
ufw allow 7946/udp # Node communication
ufw allow 4789/udp # Overlay networking
ufw enable
Step 2: Initialise the Swarm on the Manager Node
# On VPS 1 (manager):
docker swarm init --advertise-addr 10.0.0.1
# Output includes a join token like:
# docker swarm join --token SWMTKN-1-xxxx 10.0.0.1:2377
# Get the worker join token
docker swarm join-token worker
Step 3: Join Worker Nodes
# On VPS 2 (worker):
docker swarm join --token SWMTKN-1-xxxx 10.0.0.1:2377
# On VPS 3 (worker):
docker swarm join --token SWMTKN-1-xxxx 10.0.0.1:2377
# Verify on manager:
docker node ls
# ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
# abc123 * vps1 Ready Active Leader
# def456 vps2 Ready Active
# ghi789 vps3 Ready Active
Step 4: Deploy a Stack
Docker Swarm uses docker stack deploy with a Compose file. Create /opt/myapp/docker-stack.yml on the manager:
version: '3.8'
services:
web:
image: your-registry/myapp:latest
deploy:
replicas: 3 # 3 containers spread across nodes
update_config:
parallelism: 1 # Update one container at a time
delay: 10s # Wait 10s between updates
failure_action: rollback
restart_policy:
condition: on-failure
max_attempts: 3
placement:
constraints:
- node.role == worker # Only run on worker nodes
ports:
- "8080:8080"
environment:
- NODE_ENV=production
networks:
- app-network
redis:
image: redis:7-alpine
deploy:
replicas: 1
placement:
constraints:
- node.hostname == vps1 # Pin Redis to a specific node
volumes:
- redis-data:/data
networks:
- app-network
nginx:
image: nginx:alpine
deploy:
replicas: 2
placement:
constraints:
- node.role == worker
ports:
- "80:80"
- "443:443"
configs:
- source: nginx-config
target: /etc/nginx/nginx.conf
networks:
- app-network
networks:
app-network:
driver: overlay
attachable: true
volumes:
redis-data:
configs:
nginx-config:
file: ./nginx.conf
# Deploy the stack
docker stack deploy -c docker-stack.yml myapp
# Monitor service status
docker service ls
docker service ps myapp_web
Step 5: Rolling Updates
# Update app to new image version — zero downtime
docker service update \
--image your-registry/myapp:v2.0.0 \
--update-parallelism 1 \
--update-delay 15s \
myapp_web
# Monitor the rolling update
docker service ps myapp_web
# If update causes failures, automatic rollback triggers
# Or manually roll back:
docker service rollback myapp_web
Step 6: Shared Storage for Stateful Services
Swarm containers may run on any node, so stateful data must be accessible from all nodes. Options:
Option A: NFS Shared Volume
# On manager node — install NFS server
apt install nfs-kernel-server -y
mkdir -p /mnt/swarm-data
echo "/mnt/swarm-data 10.0.0.0/24(rw,sync,no_subtree_check)" >> /etc/exports
exportfs -a
systemctl restart nfs-kernel-server
# On all worker nodes — mount NFS
apt install nfs-common -y
mount 10.0.0.1:/mnt/swarm-data /mnt/swarm-data
# In docker-stack.yml — use NFS volume
volumes:
shared-data:
driver: local
driver_opts:
type: nfs
o: addr=10.0.0.1,rw
device: ":/mnt/swarm-data"
Option B: External Database (Recommended)
Keep stateful data (databases, file uploads) outside the Swarm — in a dedicated database server or object storage. Swarm containers remain stateless and can move freely between nodes without data locality issues.
Step 7: Swarm Secrets Management
# Store secrets securely in Swarm (encrypted at rest and in transit)
echo "StrongDatabasePassword" | docker secret create db_password -
echo "your-api-key-here" | docker secret create api_key -
# Reference in stack file
services:
web:
secrets:
- db_password
- api_key
environment:
- DB_PASSWORD_FILE=/run/secrets/db_password
secrets:
db_password:
external: true
api_key:
external: true
Swarm mounts secrets as files in /run/secrets/ inside containers — never as plaintext environment variables.
Step 8: Monitoring the Swarm
# Deploy Portainer for visual Swarm management
docker volume create portainer_data
docker service create \
--name portainer \
--publish 9000:9000 \
--constraint 'node.role == manager' \
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
--mount type=volume,src=portainer_data,dst=/data \
portainer/portainer-ce:latest
# Access Portainer at http://MANAGER_IP:9000
Portainer provides a web UI to manage services, view running containers across all nodes, check logs, and deploy new stacks without command-line access.
Conclusion
Docker Swarm on multiple Hong Kong VPS instances provides high availability and horizontal scaling for containerised Asia-Pacific applications — with native rolling deployments, encrypted secrets management, and overlay networking spanning all nodes. The setup is significantly simpler than Kubernetes while providing the multi-node resilience that single-VPS deployments cannot offer.
Scale your cluster: Browse Server.HK Hong Kong VPS plans — start with two or three 4 GB VPS instances for a production-ready three-node Swarm cluster.