jcanfield
7/26/2016 - 8:56 AM

Run docker-compose with docker-machine and docker-swarm on digital ocean

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