Join our Discord Server
Getting Started

Lab 18: The ‘Scale’ Command

Estimated reading: 2 minutes 100 views

The docker-compose scale <service name> = <no of instances> sets the number of containers to run for a service.

NOTE:The scale command is deprecated, instead Use the up command with the –scale flag.
docker-compose up --scale <service name> = <no of instances>

Pre-requisite:

Tested Infrastructure

Platform Number of Instance Reading Time
Play with Docker 1 5 min

Pre-requisite

  • Create an account with DockerHub
  • Open PWD Platform on your browser
  • Click on Add New Instance on the left side of the screen to bring up Alpine OS instance on the right side

Assignment

  • Create a docker-compose.yml file
  • Bringing up the containers
  • Listout the services
  • Scale service

Create a docker-compose.yml file

version: '3.1'
services:
   redis-master:
     image: redis:latest 
     container_name: webserver
     restart: unless-stopped
     ports:
       - "6379"
   redis-slave: 
     image: gcr.io/google_samples/gb-redisslave:v1 
     ports: 
       - "6379"
     environment: 
       - GET_HOSTS_FROM=dns
   frontend: 
     image: gcr.io/google-samples/gb-frontend:v3 
     ports: 
       - "80:80" 
     environment: 
       - GET_HOSTS_FROM=dns

Bringing up the containers

$ docker-compose up -d

Checking container status

$ docker-compose ps
       Name                     Command               State            Ports         
-------------------------------------------------------------------------------------
root_frontend_1      apache2-foreground               Up      0.0.0.0:80->80/tcp     
root_redis-slave_1   /entrypoint.sh /bin/sh -c  ...   Up      0.0.0.0:32769->6379/tcp
webserver            docker-entrypoint.sh redis ...   Up      0.0.0.0:32768->6379/tcp  

Listout the services

$ docker-compose ps --services
redis-slave
frontend
redis-master

Scale service

$ docker-compose scale redis-slave=3
Starting root_redis-slave_1 ... done
Creating root_redis-slave_2 ... done
Creating root_redis-slave_3 ... done

Checking container status

$ docker-compose ps
       Name                     Command                State              Ports         
----------------------------------------------------------------------------------------
root_frontend_1      apache2-foreground               Up         0.0.0.0:80->80/tcp                      
root_redis-slave_1   /entrypoint.sh /bin/sh -c  ...   Up         0.0.0.0:32772->6379/tcp
root_redis-slave_2   /entrypoint.sh /bin/sh -c  ...   Up         0.0.0.0:32775->6379/tcp
root_redis-slave_3   /entrypoint.sh /bin/sh -c  ...   Up         0.0.0.0:32776->6379/tcp
webserver            docker-entrypoint.sh redis ...   Up         0.0.0.0:32768->6379/tcp

NOTE: Host machine can only bind an unallocated port to the container, so trying scale service which is mounted to host will fail.

Share this Doc

Lab 18: The ‘Scale’ Command

Or copy link

CONTENTS
Join our Discord Server