Home > Back-end >  How can I rescale an already running docker-compose without restarting containers?
How can I rescale an already running docker-compose without restarting containers?

Time:01-03

I am running a docker-compose stack with two services and I would like to scale/rescale one of them multiple times.

This is my docker-compose.yaml file:

version: '3.8'
services:
  manager:
    hostname: manager
    build:
      context: .
      dockerfile: manager.ubuntu.Dockerfile  
    restart: always
    ports:
      - '7777:80'
    volumes:
      - './src:/src'
      - './app:/var/www/html'
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker    
    tty: true
    networks:
      - my-net      
  worker:
    build:
      context: .
      dockerfile: worker.dind.Dockerfile  
    restart: always
    privileged: true    
    tty: true
    networks:
      - my-net            
networks:
  my-net:

I am scaling like this:

docker-compose -p stack up --scale worker=3 --build

This is the first result:

...   NAMES
...   stack_manager_1
...   stack_worker_1
...   stack_worker_2
...   stack_worker_3

Now that I have 3 workers and 1 manager running I would like sometimes to rescale to add for example 2 more workers without affecting the current state of other containers.

The expected result after rescale

...   NAMES
...   stack_manager_1
...   stack_worker_1
...   stack_worker_2
...   stack_worker_3
...   stack_worker_4
...   stack_worker_5

Is there any possible way to do that where I don't want any container to be stopped or restarted but just add additional containers to the stack?

CodePudding user response:

You can do it with "--no-recreate" like:

docker-compose -up -d --scale worker=3 --no-recreate

Check out:

docker docs

  • Related