Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to `--scale` from within docker-compose file

Let's say I have the following docker-compose.yml file:

version: '3'

services:
    load-balancer:
        ...
        ...

    web-application:
        ...
        ...

If I want to run this with 5 replicas of web-application, I have to issue this command:

docker-compose up --scale web-application=5

Is there any way to tell Docker to do the --scale web-application=5 bit from within the docker-compose.yml file?

like image 768
shinvu Avatar asked Sep 07 '25 01:09

shinvu


2 Answers

You can specify the number of replicas in docker-compose only when working in swarm mode.

See the deploy directive.

Example:

services:
  redis:
    image: redis:latest
    deploy:
      replicas: 2

From the documentation:

This only takes effect when deploying to a swarm with docker stack deploy, and is ignored by docker-compose up and docker-compose run.

Lastly, there is some discussion about this feature (since it used to be possible) in this GitHub issue, and here is the mention in the most recent compose spec.

like image 84
DannyB Avatar answered Sep 09 '25 23:09

DannyB


I tested replicas in docker compose file, the code that worked for me is the following. docker container example with 5 replicas

You should use docker-compose up -d to execute the configuración

You should see the next results. results.

The results in web browser should be the following: nginx in web browser

like image 31
Jorge Santos Neill Avatar answered Sep 09 '25 23:09

Jorge Santos Neill