Skip to content

Instantly share code, notes, and snippets.

@alancnet
Last active September 29, 2020 12:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alancnet/326ee262e5ddceec0f9d to your computer and use it in GitHub Desktop.
Save alancnet/326ee262e5ddceec0f9d to your computer and use it in GitHub Desktop.
How to Docker Swarm

Temporary environment variables

# IP Address of master machine
masterip=192.168.0.101

# IP Address of node machine
nodeip=192.168.0.14

On the master

Run ETCD

docker run -d --restart always -p 4001:4001 -p 7001:7001 --name swarm-etcd microbox/etcd --name swarm-etcd

Run the manager

docker run -d --name swarm-manager --restart always -p 3375:2375 swarm manage etcd://$masterip:4001

On each node

Run the daemon

docker run -d --name swarm-proxy --restart always -p 2375:2375 -v /var/run/docker.sock:/var/run/docker.sock ehazlett/docker-proxy:latest

Join the cluster

docker run --restart always -d --name swarm-join swarm join --advertise $nodeip:2375 etcd://$masterip:4001

Start a container on the cluster

docker -H tcp://$masterip:3375 run --rm docker ping -c 5 4.2.2.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment