Docker swarm - rahulsharesth/docker GitHub Wiki
Pre-requisites
You will need all of the following in order to complete this lab:
Three nodes running Docker v1.12.x(+).
1. Create Machine -
Docker Machine is a tool that lets you install Docker Engine on virtual hosts, and manage the hosts with docker-machine commands. You can use Machine to create Docker hosts on your local Mac or Windows box, on your company network, in your data center, or on cloud providers like AWS or Digital Ocean.
docker-machine create --driver virtualbox manager
docker-machine create --driver virtualbox worker1
docker-machine create --driver virtualbox worker2
eval $(docker-machine env manager)
docker-machine ls (* is active)
Example - 192.168.99.100:2376 manager
192.168.99.101:2376 worker1
192.168.99.102:2376 worker2
You could open three terminal for VM(s)
docker-machine ssh manager
docker-machine ssh worker1
docker-machine ssh worker2
2. Pull Image from Docker Hub -
docker pull rahulsharesth/myimage
3. Run the App -
docker run -itd --name cat-app -p 8000:5000 rahulsharesth/myimage
docker container ls
Open browser - http://192.168.99.100:8000
4. Create the Swarm
docker swarm init --advertise-addr 192.168.99.100:2376
5. Join the Swarm
docker-machine ssh worker1
docker swarm join --token <<>> 192.168.99.100
docker-machine ssh worker2
docker swarm join --token <<>> 192.168.99.100
6. Create Network -
docker-machine ssh manager
docker node ls
docker network create -d overlay catnet
docker network ls
6. Create Service -
docker service create --name cat-app --network catnet -p 8000:5000 rahulsharesth/myimage
http://192.168.99.101:8000 // Worker node is up
http://192.168.99.102:8000 // Worker node is up
7. Scale the app -
Demand is crazy! Everybody loves your cats
app! It's time to scale out.
One of the great things about services is that you can scale them up and down to meet demand. In this step you'll scale the web front-end service up and then back down.
docker-machine ssh manager
Scale the number of containers in the web service to 7 with the docker service update --replicas
command. replicas
is the term we use to describe identical containers providing the same service.
docker service update --replicas 7 cat-app
docker service ls
docker service ps <<>>
8. Check the containers -
docker-machine ssh worker1
docker container ls
docker-machine ssh worker2
docker container ls