Skip to content

Instantly share code, notes, and snippets.

@ToughCrab24
Last active May 11, 2018 16:15
Show Gist options
  • Save ToughCrab24/0df8e932f15d28caf3254c7448e00ad3 to your computer and use it in GitHub Desktop.
Save ToughCrab24/0df8e932f15d28caf3254c7448e00ad3 to your computer and use it in GitHub Desktop.
Docker Swarm Setup with Docker Machine

Swarm Setup

Local

#1 Create virtual machines

docker-machine create manager1
docker-machine create worker1
docker-machine create worker2

#2 Find manager IP

docker-machine ip manager1

#3 Initialize Docker Swarm

docker-machine ssh manager1
docker swarm init --advertise-addr <manager1-ipaddress>
docker swarm join-token worker

Sample join command for a worker node

docker swarm join --token <token> <manager-ip>

#4 Join workers

docker-machine ssh worker1
docker swarm join --token <token> <manager-ip>
docker-machine ssh worker2
docker swarm join --token <token> <manager-ip>

#5 Swarm Info

docker info

#6 Deploy a service

docker service create --replicas 1 --name helloworld alpine ping docker.com

#7 Scale a service

docker service scale <SERVICE-ID>=<NUMBER-OF-TASKS>

#8 Hook local docker to swarm node

eval "$(docker-machine env manager1)"

Swarm Services

Visualizer

docker service create \
  --name=viz \
  --publish=8080:8080/tcp \
  --constraint=node.role==manager \
  --mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
  dockersamples/visualizer

Minecraft

docker service create \
  --name=minecraft \
  --publish=25565:25565/tcp \
  --constraint=node.role==worker \
  -e EULA=TRUE \
  itzg/minecraft-server

Ping Docker

docker service create --replicas 1 --name helloworld alpine ping docker.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment