Docker Swarm in  a nutshell!

Docker Swarm in a nutshell!

·

3 min read

DockerSwarm

Docker swarm is the product of docker. It is an orchestration tool that will help us to orchestrate the container deployment.

DockerSwarm is the tool that helps us manage and deploy the container across multiple VM's.

i.e., a cluster of nodes.

Note: DockerSwarm is only used to create containers using docker software other container software such as Rocket etc. will not work with dockerswarm.

Requirements

Master Node: Docker software installed up and running

Workernode: Docker software installed up and running

How to create a cluster using Docker Swarm?

Master Node:
To initiate the process run the below command on the master node

Command:

docker swarm init (It will initiate the docker swarm process for creating a cluster)

Docker on three machines with swarm from scratch - blog - Michal Szczepanski

Note: once the process is completed you will get a command for joining the slave(worker node) to the cluster. Copy everything from the docker swarm join along with the token it got generated and paste it in the Worker Node VM, for it to join the docker swarm cluster

Command:

docker swarm join-token ( Run this on slave/worker node)

How to create a service in the docker swarm cluster?

Masternode:

To create a service on docker swarm run the below command on the master node:

Command:

docker service create -name svc1 -replicas 4 -p 81:80 nginx

docker service create –name svc1 (Name of your choice) –replicas 4(No of your choice it will create replicas of the container across the cluster) -p 81:80(Binding port) nginx (Name of the image)

Once you run the above command it will create a service and that will create four containers running across the cluster both on the master and the worker node.

Note: Service port 81 will be available across the cluster

Command to list out the services created on the master node:

Command: docker service ls

Post | Dreamlab Technologies

Note: The above image is just to show how Command works

Command to check the number of nodes attached to the cluster:

Command: docker node ls

Docker Swarm: Set Up A Cluster Of Docker Engines For Achieving High  Availability | Edureka

Command to delete the service created on the master node:

Command: docker service rm services

Note: Deleting service will delete all the containers running across the cluster

Scaling up and scaling down containers using Docker Swarm:

How services work | Docker Documentation

Using docker swarm we can easily scale up or scale down our containers running across the cluster

Run the below command to scale up the container across the cluster:

Command: docker service scale svc1(NameOfTheService)=10(No of your choice)

Run the below command to scale down the container across the cluster:

Command: docker service scale svc1(NameOfTheService)=2(No of your choice)

Security with DockerSwarm:

As we have seen under services when we delete the service everything along with that service has been deleted.

To prevent any unauthorized access we can use a feature of docker swarm to lock the access to the services created.

Command: docker swarm update –autolock=true( It will generate a password for us, Store the password someplace safe because to unlock we require it)

To unlock the swarm use the below command:

Command: docker swarm unlock (It will prompt you to enter the password which got generated earlier)

Thank you!

Checkout my Medium Blog

https://medium.com/@inchararlingappa

Linkedin

https://www.linkedin.com/in/inchara-r-2b2a76213/

Instagram

https://www.instagram.com/inchara_ramalingappa/

YouTube

https://www.youtube.com/@DevOpswithIncharaRamalingappa