- [Instructor] When learning docker's swarm,
there are some important concepts, some key terms
that you need to be aware of.
They are nodes, services, containers and tasks.
So let's start off with a single node.
The node is your physical host
or could it be a virtual machine in the Cloud
that's running docker, the docker engine.
Let's say we scale up our docker infrastructure
and we add a total of three nodes.
We run a docker swarm initialize to initialize this cluster
so now we have three nodes in our docker cluster.
Let's say that we want to deploy a new service
across this docker cluster.
We use the docker service create command,
this command is going to bring up a service
across the cluster, we're going to give this service a name.
We're going to call it web app one.
We're going to say that we want this new web app one service
to be created and have six tasks
run across the swarm cluster.
The actual image that's going to be instantiated inside
this container in this case is called NGINX.
NGINX is a popular open source web server.
So to recap, the NGINX web server is going to be
brought up inside six different tasks
and run across the swarm cluster.
We're going to give it a name of web app one
and it's docker swarm that's going to execute this service
and ensure that it's always highly available,
that it's always scaled across all the nodes in the cluster.
So let's see what's going to happen.
We're going to bring up this service across
each of the different nodes in the cluster,
and it's docker swarm that's bringing up these web app tasks
across the hosts in the cluster.
In swarm terminology, the tasks are the web apps
in this case that are being brought up.
And inside of those tasks is the container image,
which in this case happens to be NGINX,
but it could be any container image that you want to deploy
as a service in the swarm cluster.
So now let's give it a try, let's actually go over
to our swarm cluster, let's execute that command
that you see there on the screen.
Let's create our new service
and bring up this web app with six replicas
running the NGINX web server.
So we'll do a docker service create,
we'll give this service a name, we'll call it web app one.
We'll say that we want to have six replicas
running at all time, and the image that we're going to
execute is NGINX.
Alright based on the service ID that we received right here,
the creation of the new service was successful.
Let's run a docker service base LS,
and you can see the same ID here.
There's the name of the web app that we created,
it says its mode is replicated,
so it has been successfully replicated.
Six of six replicas are active,
and there's the image that we executed NGINX latest.
Let's run another command,
let's run docker space PS and we can see on this node
in the cluster, we have two containers running.
These two containers were spawned
by the service that we created.
So that's on one node.
Let's go to node number two and we'll do a docker PS here.
We have two more containers running here,
two more instances of NGINX.
And then finally on node three,
again we'll do a docker PS and you can see
there are two more instances of NGINX running here
for a total of six replicas that we defined
when we created the service.
To recap, the difference between a container and a service,
a container runs only on one host.
The host that you instantiated on when you performed
the docker run command.
When you run that container on the host,
you have to manually share the networks
and the storage per container
in the docker run command string.
So storage and network configurations can be difficult
to scale when you have tens or hundreds of containers
that you need to start up.
And finally, containers are tough to scale
and make highly available.
Those just aren't features of containers.
Now with services on the other hand,
they are automatically run across however many nodes
are needed based on the number of replicas that you defined.
We saw that when we used the docker service create.
With services, high availability is simply built in.
If I were to pull the power plug on one of those nodes
in the docker cluster, the containers that were running
on that node would be automatically restarted
on other nodes based on the
docker swarm service functionality.
With services, scalability of the application
that you want to scale up, is easy to do.
You can go and modify the number of replicas for the service
and additional containers will be brought up
across the docker cluster.
And finally, exposing networks and storage is easy.
You can do it one time defining whatever networks
or storage you want to share.
And that functionality applies to all the containers
that are running as part of that service automatically.
Docker services are the better way to run containers,
because services allow you to run containers
across tens or hundreds of nodes in a docker swarm cluster
with scalability and high availability built in.