Skip to content

Instantly share code, notes, and snippets.

@noeljackson
Last active September 27, 2020 17:56
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save noeljackson/3c4b78a0002520f55dba35c6833185af to your computer and use it in GitHub Desktop.
Save noeljackson/3c4b78a0002520f55dba35c6833185af to your computer and use it in GitHub Desktop.
Run docker-compose with docker-machine and docker-swarm on digital ocean
#from https://www.linux.com/learn/how-use-docker-machine-create-swarm-cluster
#export digital ocean token
export DO_TOKEN="abcdefghijklmnopqrstuvwxyz"
#make keystore
docker-machine create -d digitalocean \
-digitalocean-access-token ${DO_TOKEN} \
--digitalocean-region "nyc1" \
--digitalocean-image="ubuntu-14-04-x64" \
--digitalocean-size "512mb" \
keystore
eval "$(docker-machine env keystore)"
#run consul
docker run --name consul --restart=always -p 8400:8400 -p 8500:8500 -p 53:53/udp -d progrium/consul -server -bootstrap-expect 1 -ui-dir /ui
# swarm master
docker-machine create \
-d digitalocean \
--digitalocean-access-token ${DO_TOKEN} \
--digitalocean-region "nyc1" \
--digitalocean-image="ubuntu-14-04-x64" \
--digitalocean-size "1gb" \
--swarm --swarm-master \
--swarm-discovery="consul://$(docker-machine ip keystore):8500" \
--engine-opt="cluster-store=consul://$(docker-machine ip keystore):8500" \
--engine-opt="cluster-advertise=eth0:2376" \
swarm-master
docker-machine create \
-d digitalocean \
--digitalocean-access-token ${DO_TOKEN} \
--digitalocean-region "nyc1" \
--digitalocean-image="ubuntu-14-04-x64" \
--digitalocean-size "512mb"\
--swarm \
--swarm-discovery="consul://$(docker-machine ip mh-keystore):8500" \
--engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500" \
--engine-opt="cluster-advertise=eth0:2376" \
swarm-1
#create overlay network
#set swarm master
eval $(docker-machine env --swarm swarm-master)
docker network create --driver overlay --subnet=10.0.9.0/24 my-net
docker network ls
#export token
export SWARM_TOKEN="03b268b9b0be689f5ddb1b8ff7beb2c2"
#remove swarm-1 it was only needed for an ID
docker-machine rm swarm-1
#make swarm master
docker-machine create -d digitalocean --digitalocean-access-token ${DO_TOKEN} --digitalocean-region "nyc1" --digitalocean-image="ubuntu-14-04-x64" --digitalocean-size "512mb" --swarm --swarm-master --swarm-discovery token://${SWARM_TOKEN} swarm-master
$(docker-machine env --swarm swarm-master)
#evel env
eval "$(docker-machine env --swarm swarm.master.ip)"
docker-compose up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment