If you are a micro services builder you have definitely come across the situation where to and how to deploy your docker containers for production without spending too much money and effort. In order to deploy the container in to production environment the platform should have few specifications.
Self Healing : The containers should be restarted if there is a execution failure. Also if a container failed to start it must be removed from the stack and replace it with the fresh container instance.
Horizontal Scaling and load balancing: If a service container is running it's maximum capacity another cloned instance should be spawned to relieve the increasing capacity. When the load becomes lower the extra spawned container should be deleted.
Docker swarm can be introduced as a small scale deployment method for the small scale production environments. But the docker officials recommend this swarm method not to use for the production environments. But as per my personal opinion swarm mode can be used for the startups whom cannot afford for the larger environments.
NOTE: Kubernetes is most sophisticated container orchestration platform for the production environments.
Features of Swarm
- Scaling: We can scale up or down the number of containers running for the given service.
- Multi-Host Networking: This swarm mode can be run on the multiple hosts. The hosts need to have a physical network connection. But for the internal inter service communication the Pods need to have a internal network.
Enable Docker Swarm in a hosted environment.
For this tutorial I will be using the Ubuntu 20.04 LTS version.
Install Docker
sudo apt-get update && sudo apt install docker.io
This installs the docker engine in the ubuntu system.Run docker as sudo less
sudo groupadd docker
sudo usermod -aG docker $USER
Change hostname to FQDNS
sudo nano /etc/hostname
It is the best practice to change the hostname to the FQDNS (manger.omigoz.net
)Enable docker swarm
docker swarm init
This will create a swarm named default with the IP address range of 10.0.0.0/8 (by default IP address range.) If you want to edit the default IP range you can use the below command.
docker swarm init --default-addr-pool 10.20.0.0/16
In docker swarm we can attach additional workers to the cluster. So there is a way to generate the join command.
docker swarm join-token worker
Also if you want to join a manager node to the cluster you need to generate the separate manger node attaching command.
docker swarm join-token manager
Ciao Omigoz
Top comments (1)
Awesome🔥