Learn and grow this Ramadan with courses up to 90% off.
Introduction to TensorFlow for AI, ML, and DL.
Blockchain Council announces 25% off SITEWIDE,sale is valid until 20th May 2019.Use Coupon Code - 2yrsblockcouncil Blockchain Certification

How to scale services using Docker Compose

Docker Compose tool is used to define and start running multi-container Docker applications. Configuration is as easy,there would be YAML file to configure your application’s services/networks/volumes etc., Then, with a single command, you can create and start all the services from the compose configuration.

Here are the key steps :

  1. Define Dockerfile for your app’s environment.
  2. Define docker-compose.yml for the services that make up your app services.
  3. Run docker-compose up and Compose starts and runs your entire app.

This quickstart assumes basic understanding of Docker concepts, please refer earlier posts for understanding on Docker & how to install and containerize applications.In this post,we can look at how to use existing Docker compose file and scale services.

docker-compose.yml looks like this:

version: "2"
image: redis:latest 
- "6379"
image: gcr.io/google_samples/gb-redisslave:v1 
- "6379" 
environment: - GET_HOSTS_FROM=dns
image: gcr.io/google-samples/gb-frontend:v3 
- "80:80" 

Key Features of Docker Compose

  • When you define Compose file,you can use project name to isolate environments from each other. This could be useful in cases like creating multiple copies of a single environment or segregate the builds by unique build number.
  • Compose caches the configuration used to create a container. When you restart a service that has not changed, Compose re-uses the existing containers.It means that you can make changes to your environment very quickly.
  • Compose preserves all volumes used by your services. When docker-compose up runs, if it finds any containers from previous runs, it copies the volumes from the old container to the new container. This process ensures that any data you’ve created in volumes isn’t lost.
  • Compose supports variables in the Compose file. You can use these variables to customize your composition for different environments, or different users.

For more information on Docker Compose,check out here.You can also refer previous posts on Docker here & here.

Get your Zoom Pro account for as low as $12.49/month with annual plan ($14.99/month without). Host up to 100 participants on HD video, record meetings to the cloud, share content, annotate, chat, and more!

In the next section,we can look at how to use existing Docker compose file and scale services.

Scale service instances

Each service defined in Docker compose configuration can be scaled using below command

Subscribe to Emails

More than 1000+ subscribers across the world trust & read Upnxtblog articles. Subscribe to emails updates!
* indicates required

docker-compose scale <service name> = <no of instances>

For example :

docker-compose scale redis-master=3

Magoosh.com GRE 728x90

Although services can be scaled but you could get arbitrary range of ports assigned since the ports are randomly assigned by Docker engine.This can be controlled by assigning port range on the ports section of compose yaml file.



image: redis:latest 

ports: - "6379-6385:6379"

Scaling can also be done by using up command as well with the --scale flag.

docker-compose up --scale redis-master=3 -d

Alternatively, in Compose file version 3.x, you can also specify replicas under the deploy section as part of a service configuration for Swarm mode.

Congrats! today we have learnt how to scale services using scale command.

Advance your IT skills and career with Cisco training from the Cisco Learning Network Store.

Like this post? Don’t forget to share it!

Additional Resources:

Also published on Medium.

How to scale services using Docker Compose
Article Name
How to scale services using Docker Compose
With Docker Compose tool,you can define and start running multi-container Docker applications.In this post,we can look at how to use existing Docker compose file and scale services.
Publisher Name
Publisher Logo
%d bloggers like this: