All of this can be found on my github repo here. After cloning you can follow the README.md instructions.
This post is mostly just to show how easy it is to get up and running with docker swarm mode and docker stack deploy.
This is an example of thumbor in docker swarm using docker stack deploy.
Initialize the swarm cluster
docker swarm initLet preemptively pull the docker images we will be using for the demo.
docker pull apsl/thumbor-nginxdocker pull apsl/thumbor*Note: You can skip the above pull steps, but this will cause your services to take longer to start on the first deploy as it will need to pull down the images at deploy time.
Using the compose file in the repo let’s deploy the services.
docker stack deploy -f docker-compose.yml imgDisplay a list of service running.
docker service lsTest our new dynamic image resizing service which has nginx in front of it.
http://localhost/unsafe/500x400/i.imgur.com/Q4FAyLw.pngThis example is the same as above but we will use multiple VMs to show how easy it is to cluster boxes. This requires docker-machine and virtualbox to be pre-installed.
We will start by using docker-machine to provision a manager for the swarm.
docker-machine create --driver virtualbox managerNow let’s provision 3 more boxes that will be our worker nodes.
docker-machine create --driver virtualbox worker1docker-machine create --driver virtualbox worker2docker-machine create --driver virtualbox worker3Now we can create the cluster
eval $(docker-machine env manager)docker swarm init --advertise-addr eth1Then run the resulting command in each worker. Here is an example output on my Mac.
eval $(docker-machine env worker1)docker swarm join \
--token SWMTKN-1-0mfm860fo4snq5pt7zodvlcbh1irdbz4iixtz91kcs1my8d2hm-ets0olq240wa04agfqaf0tf9r \
192.168.99.100:2377eval $(docker-machine env worker2)docker swarm join \
--token SWMTKN-1-0mfm860fo4snq5pt7zodvlcbh1irdbz4iixtz91kcs1my8d2hm-ets0olq240wa04agfqaf0tf9r \
192.168.99.100:2377eval $(docker-machine env worker3)docker swarm join \
--token SWMTKN-1-0mfm860fo4snq5pt7zodvlcbh1irdbz4iixtz91kcs1my8d2hm-ets0olq240wa04agfqaf0tf9r \
192.168.99.100:2377Now that we have a swarm of 4 VM let’s connect back to the manager and deploy our img stack.
eval $(docker-machine env manager)docker stack deploy -c docker-compose.yml imgdocker-machine ls will give you the IP address of each node in the swarm cluster
You should be able to hit any of those IP address and enjoy the puppy
http://192.168.99.100/unsafe/500x400/i.imgur.com/Q4FAyLw.pngYou can scale individual services by either modifying the docker-compose.yml file and running docker stack deploy -c docker-compose.yml img or running scaling commands as a one off docker service scale img_nginx=3
If you are a more visual person you can run manomarks docker swarm visualizer on the manager
eval $(docker-machine env manager)docker run -it -d -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock manomarks/visualizerhttp://192.168.99.100:8080© 2017 Jonathan's Site
The opinions expressed here represent my own and not those of my employer or any other groups I am associated with.