Launch 3 instances, 1-manager, other 2-workers, and SSH it...
Set up Docker: Install Docker in all the instances, and check the version..
sudo apt install docker.io docker -v
Initialize a Docker Swarm:
On a manager instance, initialize a Docker Swarm cluster by running the following command:
docker swarm init
This command will provide you with a token that you can use to join worker nodes to the swarm.
Enable the 2377 port in all the instances...
Join Worker Nodes:
On each worker instance, run the following command and replace
<manager-ip>
with the IP address of your manager node and<token>
with the token provided in the previous step:docker swarm join --token <token> <manager-ip>:2377
copy this and paste it into both worker instances
This will add the worker node to the Docker Swarm cluster.
List the nodes (both manager and worker nodes) in your Docker Swarm cluster
To deploy the application on the Docker Swarm servers, let's pull an image from my repository.
Create a service on the Docker manager node server to install the application using the Docker image from Docker Hub.
sudo docker service create --name <service-name> --replicas <number-of-replicas> --publish <published-port>:<target-port> <image-name>:<image-tag>
Check the running containers in all the instances.
sudo docker ps
Now to access our application in the browser, we need to enable the destination port.
Edit inbound rules and allow 8000 port in all the instances
Now, we can access the application on each instance by specifying the respective port number.
Manager instance
worker-1 instance
worker-2 instance
Thank you so much for reading
Follow me on LinkedIn to see interesting posts like this : )