- [Instructor] Let's take a look at the Docker stack
of services that's been deployed
across our Docker swarm cluster.
So, right now it's called mystack.
If we do a docker stack ps on mystack,
we can see that it has five replicas,
and they're all currently running
across various nodes in the cluster.
Now, once you deploy a stack with a set of services,
it doesn't have to stay static forever.
You have a couple different options
for modifying this stack.
For whatever reason, you may need
to modify the number of replicas.
You might need to modify the resource allocation.
You might need to change
the network or storage configuration.
Docker swarm gives you the ability
to modify all of these things.
So, one way of going about this
would be to modify the actual service.
If we do a docker service ls,
you can see that the Docker stack that was deployed
did deploy a service called mystack_web.
And the web portion of that,
right here, the web portion after mystack.
That came from the stack file, the YAML file,
that we used to deploy the stack.
So, we could use docker service commands here, actually,
and we could use the update command
to modify the replicas.
In this case, we could change it from,
let's say, five replicas
to 20 replicas if we wanted to do that.
And we'd need to give it the name of the service.
In this case, it's mystack_web.
With the service modified, let's see what happened
to the number of replicas.
And as you can guess, we now have 20 replicas running
instead of just five as we did before.
But what's wrong with this scenario here?
Well, this was deployed based on a stack file
and that stack file is kind of like the documentation,
if you will.
So, that's one way to modify this service,
is to modify the running service live.
Another way to modify it, and probably the right way,
is to go back to the stack file,
the YAML file here,
and actually make the changes that we need to make
here in the file, and then go out and update the stack.
So, that is a possibility.
For example, we could use nano
and we could edit the docker-stack YAML file.
We can go here and we can change the number of replicas.
And this time, let's make it 30 replicas.
And we'll change the memory allocation to 100 meg,
we'll limit it to 100 meg.
And we'll limit it to
one CPU instead of .1 CPUs.
And oh yeah, we could even go in here
and we can change the network ports if we wanted to do that.
We could add another service.
For now, let's leave it as it is.
I'll press Control+X to exit.
Say yes, and rewrite this file.
So, let's clear the screen.
And what we can do now
is we can do a docker stack.
And there's the option to do a docker stack deploy.
And notice how it says here docker stack deploy
can be used to deploy a new stack
or to update an existing stack.
So, really all we need to do here
is to re-run
docker stack deploy.
And in fact, if we just brought up,
we could just re-run that command
referencing the docker-stack file,
and it would update the stack.
So, that's what we're doing now.
And it says it's updating the service.
So, now let's do a docker service ls.
And there we go, you can see 30
is now the number of replicas.
We could also do a docker stack ps on mystack.
Wow, you can see now that we do have 30 replicas running.
So, the number of replicas was updated
when we updated the Docker stack.
And along with that, the CPU and memory limits
that we reconfigured, those were also updated.
But it doesn't have to stop there.
You could also add additional services,
additional replicas for those services,
as well as make network and storage resources
available to those services.