We have just recently launched the Docker Swarm Cluster package, a pre-configured automation solution for creating numerous Docker Engine nodes that are interconnected. These nodes are run in a swarm node and constitute a high-available and reliable cluster. This solution is beneficial for Docker based application hosting as it allows running Docker images as swarm services and easily scales them up to a particular number of replicas. This offers high availability, protection in terms of failure and distribution of workload between the members of cluster.
This article represents deployment of service to Docker Swarm cluster from a Docker stack yaml file that is predefined. We will also cover the basic steps needed for your project management.
Since Docker Cloud has shutdown, one of the major decisive points in terms of choosing a new platform for swarm cluster hosting is the Milesweb out-of-box UI management panel.
Basic Management Operations & Service Deployment
In case, you don’t have a Docker Swarm cluster yet, get it within minutes by following the linked instructions and connect to your swarm in any preferred way, e.g. access via Jelastic SSH Gate, Portainer GUI and Docker Machine.
After connecting to Docker Swarm manager node (MilesWeb SSH Gate in this example), you will be able to start your cluster management. For example, you can check the list of nodes your swarm cluster consists of by performing the next line of code:
1 |
docker node ls |
The image below represents 1 manager and 2 worker containers in our swarm cluster. A single Leader is elected automatically by the manager nodes for performing orchestration tasks whereas the remaining managers (if any) are marked as Reachable to tolerate failures.
Let’s check the process of a service deployment (both manual and automated flows) to the received clusterized solution.
Manual Swarm Services Deployment
It is possible to run any Docker image as a swarm process manually within your cluster.
1. Execute the command below for creating a process (follow the linked page to learn about the possible additional options):
1 |
docker service create –name {name} {image} |
where
- {name} – any preferred name for the process
- {image} – any desired Docker image (e.g. dockersamples/static-site)
2.Check your services with the below command:
1 |
docker service ls |
The image above displays the process of added my-service is running alongside the default portainer one (if such option was selected was selected during installation of swarm cluster).
3. For improved reliability, it is important to update the service via replications and at same time publish it to get the access from over the internet.
1 |
docker service update –replicas {replicas} –publish-add {ports} {service} |
where
- {replicas} – a number of replicas to create for process
- {ports} – two colons separated ports (i.e. published – for publishing service to and target – port on the deployed Docker image), e.g. 8080:80
- {service} – name of a service to be updated
All replicas require a minute to set up so, it’s better to wait.
4. Now, it is possible to access your image via the specified port (8080 in this case):
5. For removing any process, execute the following code:
1 |
docker service rm {service} |
This is the basic management of the swarm services. For exploring more advanced options, please follow the official documentation.
Automated Service Deployment with Stack File
For the automatic deployment of your service, the appropriate Docker Compose file is needed where all the deployment actions are listed.
1. This type of stack file can be created with any editor (e.g. vim) or by fetching it from an external source (e.g. with curl).
In this case, we have downloaded several resources for the example of voting application which will help in finding if point A (Cats) is more popular than point B (Dogs) as per the real user choices. The result of this voting will be displayed in the form of relative percentage of voters’ preferences.
2. For deploying your app, execute the below command and provide the stack file:
1 |
docker stack deploy -c {compose-file} {name} |
where:
- {compose-file} – the file you’ve prepared in the previous step (docker-stack.yml in our case)
- {name} – any prefered name (for example, VotingApp)
3. It’s now the time to check the services running on the swarm cluster with the below command:
1 |
docker service ls |
The above image displays the working of all services mentioned in the docker stack file (wait for sometime if some REPLICAS aren’t working yet). The PORTS column will help you to find the port number a particular service is running at (e.g. 5000 for voting and 5001 for results output in this case).
4. At last, access your service through the browser and mention the appropriate port (if needed) to the address:
This way you get additional service reliability by getting the automatic ensured failover protection and workload distribution evenly when hosting your dockerized services within Docker Swarm cluster. The Docker Swarm solution, pre-packaged by MilesWeb for one-click installation offers you all of the benefits mentioned above just in few minutes.