How can we help?
Categories
< All Topics
Print

Installing and Using Docker Swarm for Container Orchestration on ServerStadium

This tutorial covers the setup of Docker Swarm for orchestrating containers on ServerStadium infrastructure.

Prerequisites

Step 1: Prepare Your ServerStadium VMs/Dedicated Servers

  1. Choose Your Servers: Select multiple VMs or dedicated servers from ServerStadium. For a Docker Swarm cluster, you’ll need at least one manager node and several worker nodes.
  2. Initial Server Setup: Connect to each server via SSH. Update your systems:

    sudo apt update
    sudo apt upgrade

Step 2: Install Docker

Install Docker on each server:

sudo apt install docker.io

Start and enable Docker:

sudo systemctl start docker
sudo systemctl enable docker

Verify Docker installation:

docker –version

Step 3: Initialize Docker Swarm

Choose one server to act as the manager node:

  1. Initialize Swarm Mode:

    On the manager node, initialize Docker Swarm:

    docker swarm init –advertise-addr [manager-node-ip]


    Replace [manager-node-ip] with the manager node’s IP address.
  2. Get Join Token:

    Get the token to join worker nodes to the swarm:

    For worker nodes:

    docker swarm join-token worker


    For additional manager nodes:

    docker swarm join-token manager

Step 4: Add Worker Nodes to the Swarm

On each worker node, use the join token obtained from the manager node:

docker swarm <span class="hljs-built_in">join</span> –token [worker-join-token] [manager-node-ip]:2377


Replace [worker-join-token] with the actual token and [manager-node-ip] with the IP of the manager node.

Step 5: Deploying Services

  1. Create Services:

    On the manager node, you can now deploy services (applications) in your swarm:

    docker service create –name my-service –replicas 3 -p 8080:80 nginx


    This example creates a service with three replicas of the Nginx container, accessible on port 8080.
  2. Inspect Services:

    Check the status of your services:

    docker service ls
    docker service inspect –pretty my-service

Step 6: Scaling and Managing the Swarm

  1. Scaling Services:

    Adjust the number of replicas for your services as needed:

    docker service scale my-service=5

  2. Managing the Swarm:

    Use various Docker Swarm commands to manage your nodes and services, such as docker node ls, docker node rm, and docker service update.

Conclusion

Your Docker Swarm is now set up and running on ServerStadium VMs or dedicated servers. This powerful tool enhances your ability to deploy, scale, and manage containerized applications.

For further guidance, visit the ServerStadium Knowledge Base or reach out to our support team.

Table of Contents