Docker Swarm is a native clustering and orchestration solution for Docker containers. It allows you to create and manage a cluster of Docker hosts, and deploy and scale applications seamlessly across the cluster.
In this tutorial, we will show you how to install Docker Swarm on Fedora Server Latest.
Before you start, make sure you have the following:
If you don’t have Docker installed on your machine, follow this guide on how to install Docker on Fedora.
To initialize a swarm, you need to have at least one node that will serve as the manager. The manager node is responsible for managing the cluster and scheduling tasks.
On your Fedora machine, open a terminal and run the following command:
sudo docker swarm init
This will initialize a new swarm and create a new manager node.
After the command completes, you will see the output:
Swarm initialized: current node (hostname) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-<token>
<ip_address_of_manager>:2377
Make a note of the join command as you will need to run it on other nodes to add them to the swarm.
To join another Fedora machine to the swarm:
sudo docker swarm join --token SWMTKN-1-<token> <ip_address_of_manager>:2377
This will join the machine to the swarm as a worker node.
After you have added worker nodes to the swarm, you can deploy a service on the swarm. A service is a group of tasks that are scaled across the nodes in the swarm.
To deploy a service, you need to create a Docker Compose file that describes the service.
Create a new file named docker-compose.yml
:
nano docker-compose.yml
Add the following code to the file:
version: '3'
services:
web:
image: nginx:latest
deploy:
replicas: 3
placement:
constraints: [node.role == worker]
This docker-compose file will deploy an Nginx service with three replicas on the worker nodes.
Save and close the file.
To deploy the service, run the following command:
sudo docker stack deploy --compose-file docker-compose.yml mystack
This will create a new stack named ‘mystack’ and deploy the service to the swarm.
To list the services running on the swarm, run:
sudo docker service ls
This will display a list of all the services running on the swarm.
Congratulations, you have now successfully installed Docker Swarm on Fedora Server Latest and deployed a service to the swarm.
If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!
Alternatively, for the best virtual desktop, try Shells!