Scaling a service
Now, let’s, for a moment, assume that our sample application has been live on the web and become very successful. Loads of people want to see our cute animal images. But now we’re facing a problem: our application has started to slow down. To overcome this problem, we want to run multiple instances of the web
service. With Docker Compose, this is readily done.
Running more instances is also called scaling out. We can use this tool to scale our web
service up to, say, three instances:
$ docker compose up --scale web=3
If we do this, we are in for a surprise. The output will look as in the following screenshot:
Figure 11.19 – Output of docker-compose --scale
The second and third instances of the web
service fail to start. The error message tells us why we cannot use the same host port, 3000
, more than once. When instances 2 and 3 try to start, Docker realizes that port 3000
is already taken by the first instance...