0% found this document useful (0 votes)
3 views1 page

Docker Swarm Setup

The document outlines the steps to set up a Docker Swarm, including initializing the swarm on the manager node and joining worker nodes using a provided token. It also describes how to create and manage services within the swarm, including auto-healing capabilities and deploying a service stack with multiple containers. Additionally, it provides commands for listing and removing services, as well as scaling services within the stack.

Uploaded by

piyush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Docker Swarm Setup

The document outlines the steps to set up a Docker Swarm, including initializing the swarm on the manager node and joining worker nodes using a provided token. It also describes how to create and manage services within the swarm, including auto-healing capabilities and deploying a service stack with multiple containers. Additionally, it provides commands for listing and removing services, as well as scaling services within the stack.

Uploaded by

piyush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Docker swarm setup

1. apt-get update
2. apt-get install docker.io on all servers
3. sudo docker swarm init ---on manager node to initialize the swarm.
THe output of the above command will give a docker swarm join command
eg. docker swarm join --token SWMTKN-1-
0tptbzdpaaj11m4vhscjnarctx2sn8zwzmcyjgs2wzu1bq73st-2fpy9ttoqusd17msygffk6bus
172.31.33.118:2377
2377 is the port on worker node on which the worker nodes will connect.
Hence make sure SG of the manager node allws 2377 port to all workers

4.Install and start docker on workers and run the docker swarm join token...
command
THis way all workers will get connected to the manager

5. Now on the manager we will run a service using the following command.
sudo docker service create --name react_todo --replicas 2 --publish 8001:8001
trainwithshubham/react-django-app:latest

Port 8001 should be open for all manger and worker.


THis service will run on all servers, even if a container gets stopped or
crashes, it will auto launch itself as lng as service is running, this is called
auto healing.

6. sudo docker service ls ----to list services


sudo docker service rm <servicename> ---- to delete a service.

7. Now we write a service stack that will be able to launch multiple


services(containers) with different images.
eg.

version: '3.7'

services:
reactapp:
image: trainwithshubham/react-django-app:latest
ports:
- "8001:8001"
mysqldb:
image: mysql:latest
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: test123

8. To run a stack use the command:


sudo docker stack deploy -c stackfile.yaml stackname

docker service scale react-app_reactapp=2 ------this will lauch 2 containers


of the service react-app_reactapp

You might also like