Skip to content

This repository sets up a Docker Swarm cluster in AWS EC2. I used this for learning Docker Swarm.

Notifications You must be signed in to change notification settings

foroozf001/docker-swarm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker-Swarm

Bootstrapping the nodes

Leader:

docker swarm init

Worker:

docker swarm join --token SWMTKN-1-35...y2neeposi4ou 10.0.16.204:2377

Creating Swarm service

docker service create --replicas=5 --name=www --publish=8080:80 nginx

Inspecting Swarm cluster

docker node ls
docker node inspect sgxi2ho9rs2dtlrqojuuftuqu --pretty
docker service ls
docker service ps www
docker service inspect www --pretty

Scaling Swarm service

docker service scale www=5
docker service update --replicas=5 www

Global Swarm services

Global Swarm services are essentially the same as Kubernetes DaemonSets. The service instructs each node to run one such task.

docker service create --name=runsOnEveryNode --mode=global -dt ubuntu

Draining Swarm nodes

docker node update --availability=drain swarm03
docker node update --availability=active swarm03

Locking Swarm cluster

The Swarm certificates are located /var/lib/docker/swarm/certificates.

  • swarm-node.crt
  • swarm-node.key
  • swarm-root-ca.crt
docker swarm update --autolock=true

Fetching the key:

docker swarm unlock-key

Rotating the key:

docker swarm unlock-key --rotate

Mounting volumes in Swarm

docker service create --name=www --mount=type=volume,source=myvolume,target=/mypath nginx

Scheduling Swarm services

docker node update --label-add=regions=nl-ams swarm02
swarm02
docker node inspect swarm02 --format='{{.Spec.Labels}}'
docker service create --name=www --constraint=node.labels.regions==nl-ams --replicas=3 nginx

Swarm overlay network

Create encrypted traffic between containers in overlay network; that is across nodes:

docker network create --driver=overlay --opt=encrypted myOverlayNetwork
docker service create --name=bb --network=myOverlayNetwork --replicas=3 -dt busybox

Swarm service templates

docker service create --name=myApp --hostname="{{.Node.Hostname}}-{{.Service.Name}}" nginx

Swarm recover from losing Quorum

Run this command from another leader node:

docker swarm init --force-new-cluster

About

This repository sets up a Docker Swarm cluster in AWS EC2. I used this for learning Docker Swarm.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages