Created
January 20, 2017 10:20
-
-
Save w0rldart/6e6eb74727f2bbcfb5389cde819f95b8 to your computer and use it in GitHub Desktop.
Create a cluster of Docker Engines, a.k.a a swarm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### | |
## Virtual box options | |
### | |
export VIRTUALBOX_CPU_COUNT='1' | |
export VIRTUALBOX_DISK_SIZE='10000' | |
export VIRTUALBOX_MEMORY_SIZE='512' | |
swarm_workers=2 | |
### | |
## SWARM MANAGER | |
### | |
echo | |
echo "############################" | |
echo "## Creating swarm manager ##" | |
echo "############################" | |
echo | |
docker-machine create -d virtualbox swarm-manager; manager_ip=$(docker-machine ip swarm-manager) | |
echo | |
echo " #### IP: ${manager_ip}" | |
# Init swarm | |
docker-machine ssh swarm-manager "docker swarm init --advertise-addr $manager_ip | tee /tmp/output" | |
wait $! | |
swarm_join_command=`docker-machine ssh swarm-manager cat /tmp/output | grep '^ ' | tr -d '\n' | sed 's/[\] //g'`; | |
### | |
## SWARM WORKERS | |
### | |
echo | |
echo "############################" | |
echo "## Creating swarm workers ##" | |
echo "############################" | |
for i in `seq 1 $swarm_workers`; | |
do | |
echo | |
echo " ## Creating swarm-worker-${i} and joining swarm-manager" | |
echo | |
docker-machine create -d virtualbox swarm-worker-${i}; docker-machine ssh swarm-worker-${i} "${swarm_join_command}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment