create docker swarm
1. Configure Cluster Hosts
For whichever number of servers deployed, one will be the manager node and the rest worker nodes. Manager node handles all cluster management tasks while the worker nodes run the containers. In this article, we will use two nodes, for example:
SSH to all Ubuntu server as a non-root user with sudo access.
Edit host file
/etc/hosts
in all the nodes.Add the following code in the file.
Ping all the nodes using their hostnames.
2. Install Docker CE
Install Docker CE on all the nodes. Perform all stages in this step on all nodes.
Update the system packages.
Install all required packages.
Install Docker repository signing keys.
Add the Docker repository.
Update the system packages.
Install Docker CE.
Confirm the status of Docker.
Enable the Docker service to automatically run at system boot.
Add your current user to
docker
group.
3. Create Docker Swarm Cluster
To create a Docker Swarm cluster, you will first need to initialize the swarm mode on the manager node. Then, join the worker nodes to the cluster. Strictly use the nodes IP address.
Initialize the swarm mode.
Go to the worker-1 node and add it to the cluster. Modify the
--token
value with your own.Go to the manager node and verify if all the worker nodes successfully joined the cluster.
4. Deploy Application to the Cluster
Go to the manager node and create a 'Docker getting started web-page' service named
docker-tutorial
that will run on default http port 80 and expose it to port 80 on the host server.Verify the status of the created service.
5. Create Replicas of the Service
With two nodes in our cluster, we will make two replicas of the service. This will enable access to the service form both the manager and worker nodes.
Create replicas.
Verify the status of the service replicas.
Go to your browser and access the service from all your nodes. For example:
manager node.
worker-1 node.
Additional commands
References
Last updated
Was this helpful?