Scaling Services

Scaling our app to handle multiple requests

We'll cover the following

Right now, you may be in a situation where you don’t know how to handle these Docker services because, in swarm mode, most of the commands we used earlier won’t work exactly as expected. For example, try removing an app container. As soon as you stop a container, the swarm manager will create a new one because the default state was to have one app and one database container.

So, if you want to stop your app, you can only do that by stopping the service itself.

Scaling app containers

You can deploy multiple containers on a different node. If there are multiple nodes in the cluster, the swarm manager will create container copy on every other node until it covers all the nodes or the defined number of containers are created.

And if there is only a single node in the cluster, all the containers are created in only that node.

We will scale our app to have three app containers and two database containers.

Let’s see this in action. If you haven’t stopped the services, then type docker service scale <service ID/Name>=Replicas_number.

$ docker service scale rnlrh4e262ae=3
rnlrh4e262ae scaled to 3
overall progress: 3 out of 3 tasks
1/3: running   [==================================================>]
2/3: running   [==================================================>]
3/3: running   [==================================================>]verify: Service converged

$ docker service scale database=2
database scaled to 2
overall progress: 2 out of 2 tasks1/2: running   [==================================================>]
2/2: running   [==================================================>]verify: Service converged

Get hands-on with 1200+ tech skills courses.