1

Is it possible to run say 100 containers using same docker image but should take multiple config files? If yes, could you explain with some example docker-compose.yml file? I'm trying it for running cloudprober tool by google. version: '2' services: s1: image: generic_cloudprober
ports: - "5001:9313" command: --config_file cloudprober.cfg this is one type I have tried by repeating to 100 times. Here the targets were unable to give me response , but if I run only one container by giving config file while starting image there isn’t any issue. Also for many container with multiple confiig files( I have created few and tried) i got response as killed and exited process.

Rohith
  • 23
  • 5
  • Hi. Please show us your `docker-compose.yml` file with an honest attempt to fulfill your requirement then explain the error message you get or the problem you cannot solve at this point. – Zeitounator Apr 26 '21 at 15:02
  • version: '2' services: s1: image: generic_cloudprober ports: - "5001:9313" command: --config_file cloudprober.cfg this is one type I have tried by repeating to 100 times. Here the targets were unable to give me response , but if I run only one container by giving config file while starting image there isn’t any issue. Also for many container with multiple confiig files( I have created few and tried) i got response as killed and exited process. – Rohith Apr 26 '21 at 15:19
  • 3
    Please do not paste the code in comments, [edit your question](https://stackoverflow.com/posts/67268985/edit). You would also benefit taking the [tour](/tour) and reading the help section starting with [how to ask](/help/how-to-ask) and [how to create a minimal complete verifiable example](/help/mcve) to get the best experience here. – Zeitounator Apr 26 '21 at 15:22
  • Rohith, Please edit your question by showing the error and also the issue you are trying to solve – Giriteja Bille Apr 26 '21 at 15:31

2 Answers2

1

Yes its possible, but depending on how many different configurations you want to deploy for the 100 containers, it might be easier without using docker-compose.

Approach 1: Using a script without docker-compose

See the first two answers here You would need to create a script, that launches

docker run --net host -v /tmp/cloudprober.cfg:/etc/cloudprober.cfg \
    cloudprober/cloudprober

multiple times with each time passing in your respective configuration file. Or you can pass config via environment variables, if that is sufficient for you.

Approach 2: docker-compose up --scale See answers to this question. Let's say you have 2 different configurations (prod and dev). And want to run 50 containers for each configuration.

Make two docker-compose.yml, one in folder dev, one in folder prod.

dev/docker-compose.yml

cloudprober-dev: 
  image: cloudprober/cloudprober
  volumes:
    - /tmp/cloudprober-dev.cfg:/etc/cloudprober.cfg

prod/docker-compose.yml

cloudprober-prod: 
  image: cloudprober/cloudprober
  volumes:
    - /tmp/cloudprober-prod.cfg:/etc/cloudprober.cfg

Then run your compositions using the scale option.

cd dev
docker-compose up --scale cloudprober-dev=50
cd ../prod
docker-compose up --scale cloudprober-prod=50
nulldroid
  • 1,150
  • 8
  • 15
0

Yes its possible to run multiple container with same image. you have to define different docker-file for each container or you can combine in single docker-compose as i did in very small example. i used same postgresql image and interestingly same volume with different username and password( you can define configuration for each container as per your requirement)

version: "3.9"
  
services:
  db:
    image: postgres
    volumes:
      - ./data/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgre


  db2:
    image: postgres
    volumes:
      - ./data/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres2
      - POSTGRES_PASSWORD=postgre2

it will run two container with same image with different conf.

CONTAINER ID   IMAGE      COMMAND                  CREATED              STATUS         PORTS      NAMES
46105f7fdf9c   postgres   "docker-entrypoint.s…"   About a minute ago   Up 5 seconds   5432/tcp   compose_db2_1
fce9b8e2fc62   postgres   "docker-entrypoint.s…"   About a minute ago   Up 4 seconds   5432/tcp   compose_db_1

For more reference please find this documentation reference: https://docs.docker.com/compose/compose-file/compose-file-v3/

NOTE1 : be aware of version. NOTE2: I agree with @Zeitounator while posting your question you must give details of what you have done with proper configuration information. As you are new contributor we love to encourage you to follow the guidelines.

Vinod
  • 515
  • 4
  • 11