Andre Dixon
Andre Dixon

Reputation: 360

Docker run multiple instances of container without --scale

I have docker-compose.yml which is running a simple web server. I want to create multiple instances of the container without --scaling in the start command. This is how I currently start multiple instances of the container docker-composer up -d --scale appserver=2.

Ideally, I would love to put some kind of instruction in the docker-compose.yml to do this. Below is an example of the docker-compose.yml

version: '3'
services:
  appserver:
    image: nimmis/apache
  haproxy:
    image: eeacms/haproxy
    ports:
      - '80:5000'
      - '1936:1936'
    environment:
      BACKENDS: 'appserver_1:80 appserver_2:80 appserver_3:80'
      DNS_ENABLED: 'true'
      LOG_LEVEL: info

Note here that I am only trying to multiple instances of appserver service.

Upvotes: 0

Views: 1600

Answers (1)

BMitch
BMitch

Reputation: 263587

Docker compose doesn't support the deploy section, but if you switch to a single node Swarm Mode (as easy as running docker swarm init) you can deploy with:

docker stack deploy -c docker-compose.yml stack_name

using the following yaml:

version: '3'
services:
  appserver:
    image: nimmis/apache
    deploy:
      replicas: 2
  haproxy:
    image: eeacms/haproxy
    ports:
      - '80:5000'
      - '1936:1936'
    environment:
      BACKENDS: 'appserver_1:80 appserver_2:80 appserver_3:80'
      DNS_ENABLED: 'true'
      LOG_LEVEL: info

Upvotes: 2

Related Questions