Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose create services with a loop

Is it possible to create services in a loop with docker-compose rather than typing all the services by hand? (See example below of creating 100 workers with appropriate ports)

version: '3'
services:
  redis:
    image: redis
  worker1:
    build: .
    ports:
    - "5001:5001"
  worker2:
    build: .
    ports:
    - "5002:5002"
  worker3:
    build: .
    ports:
    - "5003:5003"

  ...

  worker100:
    build: .
    ports:
    - "5100:5100"
like image 201
Tuan Avatar asked May 15 '18 12:05

Tuan


Video Answer


1 Answers

You can probably do it with the --scale option, so if you run docker-compose up --scale worker=100 it should do exactly what you want.

The documentation for docker-compose up references this as follows:

--scale SERVICE=NUM        Scale SERVICE to NUM instances. Overrides the
                           `scale` setting in the Compose file if present.
like image 180
Chris Bailey Avatar answered Oct 08 '22 22:10

Chris Bailey