# Docker Overlay - HOW TO # These instructions describe how to deploy the key value store as a docker service # that spans multiple docker machines using docker swarm and overlay networking. # This configuration requires a key-value store (probably centralized) to act as the Node Directory. # If deploying the key value store and using UDP discovery to discover key-value store nodes, # then only one docker-machine can be used. # In that case, you may skip creation of "aw-swarm1" and "aw-swarm2" and all subsequent actions associated # with these docker-machines below. It may not be necessary to even create a network at all, and just # launch the service using the default network, though I didn't specifically try that configuration. # # ****************************************************************************** # *** For simplicity open ALL TCP ports in the Docker-Machine security group *** # ****************************************************************************** # Ports 2376, and 2377 must be open, along with 22, and others used (e.g. 1234) # Launch docker swarm manager node docker-machine create --driver amazonec2 --amazonec2-region us-east-1 --amazonec2-instance-type "m4.large" --amazonec2-spot-price ".18" --amazonec2-request-spot-instance --amazonec2-zone "e" aw-swarm0 # Start swarm manually docker-machine ssh aw-swarm0 "sudo docker swarm init --advertise-addr $(docker-machine ip aw-swarm0)" # Copy the token provided. It will be used to add each docker-machine to the swarm. # Launch a docker swarm worker node 1 docker-machine create --driver amazonec2 --amazonec2-region us-east-1 --amazonec2-instance-type "m4.large" --amazonec2-spot-price ".18" --amazonec2-request-spot-instance --amazonec2-zone "e" aw-swarm1 # add worker node 1 to the swarm docker-machine ssh aw-swarm1 "sudo docker swarm join --token $(docker-machine ip aw-swarm0):2377" # Launch a docker swarm worker node 2 docker-machine create --driver amazonec2 --amazonec2-region us-east-1 --amazonec2-instance-type "m4.large" --amazonec2-spot-price ".18" --amazonec2-request-spot-instance --amazonec2-zone "e" aw-swarm2 # add worker node 2 to the swarm docker-machine ssh aw-swarm2 "sudo docker swarm join --token $(docker-machine ip aw-swarm0):2377" # switch docker context to the swarm manager eval $(docker-machine env aw-swarm0) # create the overlay network docker network create -d overlay --attachable overnet # inspect the network, it should show up as an overlay with scope swarm docker network ls # if you're using the TCP Discovery, you'll need to deploy a central instance of your keyvalue store to act as the node directory # configure runserver.sh to startup the node directory # and rebuild the container as a nodedirectory container: docker build -t nodedirectory . # run the nodedirectory container using the overlay network docker run -d --rm --network overnet nodedirectory # connect to the nodedirectory container to discover it's IP address: # first find the container ID docker ps -a # now open a BASH session to the container docker exec -it bash # note the eth0 network IP (10.0.0.???). This is your centralized key value store IP address ifconfig # exit the BASH shell exit # modify the runserver.sh script. If you're using TCP Discovery, you'll now place the NodeDirectory IP into runserver.sh to instruct # all of the TCP servers where they should publish their IP address to. # now, rebuild the container as a tcp server for the key-value store docker build -t kvstore . # next, build the container on the other docker-machine swarm nodes eval $(docker-machine env aw-swarm1) docker build -t kvstore . eval $(docker-machine env aw-swarm2) docker build -t kvstore . # now come back to the swarm manager eval $(docker-machine env aw-swarm0) # next, launch your keyvalue store as a docker swarm service. The number of replica servers can be dynamically specified docker service create --name kvservice --replicas=5 --network overnet --publish 1234:1234 kvstore