Skip to content

Instantly share code, notes, and snippets.

@rwos
Created November 12, 2019 14:23
Show Gist options
  • Save rwos/2509402a79e10bde3b4f2e629339ccc0 to your computer and use it in GitHub Desktop.
Save rwos/2509402a79e10bde3b4f2e629339ccc0 to your computer and use it in GitHub Desktop.
local docker swarm cluster with docker-machine
SHELL=/bin/bash
all:
-$(MAKE) clean
$(MAKE) start
$(MAKE) join
start:
docker-machine create --driver virtualbox d1
docker-machine create --driver virtualbox d2
docker-machine create --driver virtualbox d3
clean:
docker-machine rm -f -y d1
docker-machine rm -f -y d2
docker-machine rm -f -y d3
join:
$(eval MASTER_IP := $(shell docker-machine ip d1))
@echo Master IP: $(MASTER_IP)
$(eval JOIN_CMD := $(shell \
docker-machine ssh d1 "docker swarm init --advertise-addr $(MASTER_IP)" | \
grep "docker swarm join --token"))
@echo Join Commmand: $(JOIN_CMD)
# join workers
docker-machine ssh d2 "$(JOIN_CMD)"
docker-machine ssh d3 "$(JOIN_CMD)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment