Sample 3 node Vagrant setup for getting started with Docker swarm
Install Vagrant Binary from here
Download debian/stretch64 box from vagrant using the command vagrant box add debian/stretch64
Clone this repo
git clone https://github.com/joebibe/vagrant-docker-swarm.git
cd vagrant-docker-swarm
Run vagrant up
docker run -p 8000:8000 --name dsv joebibe/vagrant-docker-swarmTo ssh into the manager node run vagrant ssh manager
To ssh into worker node run vagrant ssh worker-1 or vagrant ssh worker-2
docker swarm init --advertise-addr <manager-IP-address>:2377docker swarm join --token <token> <manager-IP-address>:2377docker node ls on the manager node to see the list of nodes and their roles(worker/manager)docker network create -d overlay <network-name>-d tells which driver to use. Currently overlay driver is being useddocker service create --name <service-name> --network <network-name> <image-name>Scale up : docker service update --replicas 7 <service-name>
Replicates the container 7 times and balances into all available nodes based on a round-robin or any such algorithms. This will launch arbitrary number of containers in each node (including manager)
Check which container is running on which node by running docker service ps <service-name>
Check how many containers are running on the current node by running docker ps or docker container ls
Scale down : docker service update --replicas 4 <service-name>
This command will destroy some of the containers on some of the nodes. Check which containers got destroyed by using the commands specified above.
Drain : Bring a node down for management purpose
docker node update --availability drain <worker-node-id>
can be found by running docker node ls
This will destroy the containers on the specified worker node and will relaunch them on available nodes
Active : Bring up a node drained for management purpose
docker node update --availability active <worker-node-id>
This will activate the drained node and will deploy further scaled up containers on this as well
docker service lsdocker network lsdocker node lsdocker service ps <service-name>Content type
Image
Digest
Size
53.8 MB
Last updated
over 6 years ago
docker pull joebibe/vagrant-docker-swarm