Docker Swarm and NGINX - A Practical Introduction to Docker Native Swarm

preview_player
Показать описание
Here is a quick demonstration on Docker Swarm getting started. Here are the commands I have used for this.

docker-machine create --driver virtualbox manager1
docker-machine ls
docker-machine create --driver virtualbox worker1
docker-machine create --driver virtualbox worker2
docker-machine ls
We have created the three vms
Get into the manager node
docker-machine ssh manager1
docker swarm init --advertise-addr 192.168.99.100
Now on to the worker nodes
docker-machine ssh worker1
docker swarm join --token SWMTKN-1-2mk0akcfd6z66izhekap0ajhrf2p6398sqg3y1x8hngwxb3aap-dzfc4urwpuelj22fbdndxnhbt 192.168.99.100:2377
docker-machine ssh worker2
docker swarm join --token SWMTKN-1-2mk0akcfd6z66izhekap0ajhrf2p6398sqg3y1x8hngwxb3aap-dzfc4urwpuelj22fbdndxnhbt 192.168.99.100:2377
Now we need to get into the manager node for all our remaining docker swarm commands!
[MANAGER NODE]
docker node ls
docker service create \
--name mynginx \
--publish 8080:80 \
--replicas 3 \
nginx
docker service ls
docker service ps mynginx
Browse the server

[MANAGER NODE]

we need to know the container ID using docker ps and use docker exec to get in

docker exec -ti [CONTAINER_ID] bin/bash

Let us repeat this on the other two worker nodes.

Let us browse and see which one is being served

Ok this page is from the manager nodes ngnx conatiner.

Let us drain this node from the service

Sorry I am inside the container, let me exit to get back to the manager node prompt.

[MANAGER NODE]
docker service ps mynginx
we have three nodes in our nginx service, let us drain the manager node from this.

docker node update --availability drain manager1
docker service ps mynginx
yes it has been removed.

Now let us refresh and see, yes now work1 is being served.

We could also scale down or up the number of nodes in a docker swarm service.

example..
$ docker service scale mynginx=2
$ docker service ps mynginx

Also docker swarm built in load balancer will auto route the incoming requests to the containers. Let us refresh and see. Instead of worker 1 now worker 2 is serving the page.

Finally in order to clean up our experiements all we need to do is to

docker-machine rm manager1 worker1 worker2

All the three machines have been removed... yes our ssh session have terminated as well.

Hope you like this docker swarm quick demo and please feel free give your valuable feedbacks.

Thank you!
Рекомендации по теме
Комментарии
Автор

Best video for docker machine...want more videos on devops sir..

umakantmali
Автор

Excellent, please add more videos on other topics as well, Thank you so much

madhukarnaidugunda
Автор

Great job with the video sir. Keep it up.

dileshj
Автор

after docker node update --availability drain in manager it will showing shutdown containers how can i up that shutdown previous containers

santhoshkumarkasarla
Автор

Good video. Thank You Sir.

just curious what is docker service ? Is that swarm ?

savithari