In this video, you'll get a quick introduction to Docker Swarm.
So what is Docker Swarm?
Well, it's a Docker solution to create a cluster or a swarm of multiple Docker hosts.
It's doing what Kubernetes is doing, basically.
Before Docker 20, Docker Enterprise Edition was needed to use Swarm.
But since Docker 20, Docker Swarm is open source and free and doesn't require any license.
So you can easily take it for a test drive.
Docker Swarm allows for handling of container scheduling, scaling, networking, and failover
automatically.
And you can see it as an easier alternative to Kubernetes.
It's not as feature rich, but it's pretty easy to get started.
In order to work with Docker Swarm, you need to be familiar with the terminology.
So a swarm refers to the entire cluster, which is a group of Docker nodes.
And nodes are the Docker hosts that are used either as a manager, which controls, or as
a worker, which runs user workloads.
A service is the description of what to run.
And that includes a container image, ports, replicas, and constraints, where replicas
can be multiple instances of the same container image.
A task is a specific container that runs in a service.
And a stack is a collection of services that makes up a microservice application.
To work with Docker Swarm, you need to know about a couple of commands.
They all start with Docker Swarm.
And Docker Swarm init creates a cluster on the first node.
Docker Swarm join allows other nodes to join the cluster.
And Docker node ls shows all the nodes in the Swarm cluster.
Docker service create, minus minus name web, minus p 8080 colon 80, creates a service based
on the nginx container image and is providing port forwarding to it using port 80.
Docker service scale, web is five, scales the web service to five running instances.
And Docker service ls gives a list of services and their replica count.
Docker stack deploy is a very useful command.
It deploys a stack as defined in a compose file.
And Docker service logs gives output generated by all containers in a service.
Let me give you a quick demo.
So I'm starting with my Docker Swarm init.
And that is making that this node is now a manager.
As you can see, it's printing a join command.
And the join command is what you can use on other nodes to add them to the Swarm cluster.
And once you're done building your Swarm cluster, you use Docker service create, minus
minus name web, minus p 80 colon 80, nginx for instance.
And as you can see, that is creating the service for you.
Now Docker service scale is what you can use to add some scalability.
So let's do a Docker service scale, web is five, to ensure that it's using five different
instances.
And then Docker service ls is showing that the service is now running.
And we have five different replicas on it.
So it is ready for business.
And that's enough about Docker Swarm.
Because after all, Docker Swarm is a topic all by itself.
And you just need to know a little bit about it.
This should be enough.