Skip to main content
added a tag
Link
Source Link

docker-compose multiple services in a loop

Trying to optimize definition of multiple services with docker-compose.yml

Here is the original, "dumb" variant of the docker-compose.yml:

version: '3'
services:
  s1:
    build: .
    ports:
    - "5001:9000"
    volumes:
    - ../www1:/var/www
  s2:
    build: .
    ports:
    - "5002:9000"
    volumes:
    - ../www2:/var/www
  s3:
    build: .
    ports:
    - "5003:9000"
    volumes:
    - ../www3:/var/www

Is there some sort of an iterator to compact this to just one block like the following?

version: '3'
services:
  for i in 1,2,3:
    s$i:
      build: .
      ports:
      - "500$i:9000"
      volumes:
      - ../www$i:/var/www