6

According to docker-compose issue #5586, scale is deprecated. The replacement is deploy.replicas but that latter is not handled by docker-compose, only by docker stack implying you have to run Docker in swarm mode.

As alternate solutions, you can scale services from the command line with docker-compose:

docker-compose up --scale app=3

I'm not too fond of this solution since in my understanding docker-compose.yml is supposed to be self-contained and should not depend on command line options.

Another option is to run docker-compose in --compatibility mode:

docker-compose --compatibility up

In that case, docker-compose will translate some deploy entries into their version 2 equivalent. But because of the name of that option, and because of the warnings in the docs, it does not look like a mid- to long-term solution.

What would you suggest to replace the docker-compose v2 scale option?

Sylvain Leroux
  • 1,550
  • 1
  • 13
  • 25

1 Answers1

3

@decoomanj on github indicated that scale has to be replaced by deploy in conjunction with replicas.

According to mrampant-nist on github one has to use --compatibility as well.

Let's test this. First of all all docker-compose.yml is needed:

version: '3.3'
services:
    nginx:
      image: nginx
      scale: 6

and issuing:

docker-compose up

results in:

ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.nginx: 'scale'

Applying @decoomanj's suggestion, i.e. replacing replicas:

version: '3.3'
services:
    nginx:
      image: nginx
      deploy:
        replicas: 6

results in:

WARNING: Some services (nginx) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm.

Running docker-compose --compatibility up starts 6 services:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
f19aa54634d7        nginx               "nginx -g 'daemon of…"   5 seconds ago       Up 4 seconds        80/tcp              6233_nginx_5
749cff4ac1c3        nginx               "nginx -g 'daemon of…"   5 seconds ago       Up 3 seconds        80/tcp              6233_nginx_3
b86ed7b217fe        nginx               "nginx -g 'daemon of…"   5 seconds ago       Up 1 second         80/tcp              6233_nginx_6
0b92e5ef4a0e        nginx               "nginx -g 'daemon of…"   5 seconds ago       Up 2 seconds        80/tcp              6233_nginx_2
e414bca52b53        nginx               "nginx -g 'daemon of…"   5 seconds ago       Up 4 seconds        80/tcp              6233_nginx_4
e9f33dc634a8        nginx               "nginx -g 'daemon of…"   6 seconds ago       Up 5 seconds        80/tcp              6233_nginx_1

In conclusion, replicas has to be replaced by deploy and replicas and --compatibility is needed to solve the issue.

030
  • 13,235
  • 16
  • 74
  • 173