4

I'm trying to create 3 mattermost services on 1 AWS EC2 machine.

Let me explain further with more texts:

When I run docker-compose up -d, I get a service whose structure is like this:

enter image description here

How can I modify the docker related scripts so that I can create 3 sets of service?

enter image description here

I've tried docker-compose up --scale app=3 --scale web=3 --scale db=3. But I can't find any way to specify different port for each of the App container.

The only solution I've found is:

  1. Create 3 copies of mattermost-docker folder.

  2. Change the App port and database connection information.

  3. Run docker-compose up -d 3 times in mattermost-docker1, mattermost-docker2, and mattermost-docker3 separately.

But this solution creates a lot of duplicated files. I don't like it.

Anyone knows how to create 3 sets of mattermost services?

Brian
  • 12,145
  • 20
  • 90
  • 153
  • I think you should 3 different files as docker-compose itself is a binary which works under the hood with Docker engine to create 3 different set of mattermost services. Also it is better for the sake of maintainability. – Janshair Khan Jul 09 '18 at 05:09
  • See if this is of any help https://tarunlalwani.com/post/docker-compose-scale-with-dynamic-configuration-part-1/ ? – Tarun Lalwani Jul 09 '18 at 05:47
  • Share content of docker compose file. – Bagira Jul 09 '18 at 06:08

2 Answers2

0

You need to specify a port range in docker compose:

For example, for 10 container scalling:

version: '3'

services:
  web:
    ...
    ports:
      - "80-90:443"

  app:
    ...
    ports:
      - "8000-8010"

Note that you don't need to change port inside container (443, 444, 445). You can use the same, and furthermore that's recommended, because although you use different containers in a port range, is easier if they use the same nginx configuration.

Alejandro Galera
  • 3,445
  • 3
  • 24
  • 42
0

This starts sets of services using 3 separate databases (nginx and mongo used as example).

  version: '3'

  services:

    web1:
      container_name: web1
      image: nginx:latest
      ports:
        - 8080:8080

    app1:
      container_name: app1
      image: nginx:latest
      ports:
        - "8081:8081"
    db1:
      container_name: db1
      image: mongo
      ports:
        - 27017

    web2:
      container_name: web2
      image: nginx:latest
      ports:
        - 8082:8082

    app2:
      container_name: app2
      image: nginx:latest
      ports:
        - "8083:8083"
    db2:
      container_name: db2
      image: mongo
      ports:
        - 27018

    web3:
      container_name: web3
      image: nginx:latest
      ports:
        - 8084:8084
    app3:
      container_name: app3
      image: nginx:latest
      ports:
        - "8085:8085"
    db3:
      container_name: db3
      image: mongo
      ports:
        - 27019

Local Test:

NAMES                STATUS                PORTS                                   IMAGE
db2                  Up About a minute     27017/tcp, 0.0.0.0:32803->27018/tcp     mongo
web1                 Up About a minute     80/tcp, 0.0.0.0:32802->8080/tcp         nginx:latest
db1                  Up About a minute     0.0.0.0:32801->27017/tcp                mongo
app1                 Up About a minute     80/tcp, 0.0.0.0:32800->8081/tcp         nginx:latest
app3                 Up About a minute     80/tcp, 0.0.0.0:32798->8085/tcp         nginx:latest
db3                  Up About a minute     27017/tcp, 0.0.0.0:32799->27019/tcp     mongo
app2                 Up About a minute     80/tcp, 0.0.0.0:32797->8083/tcp         nginx:latest
web3                 Up About a minute     80/tcp, 0.0.0.0:32796->8084/tcp         nginx:latest
web2                 Up About a minute     80/tcp, 0.0.0.0:32795->8082/tcp         nginx:latest
D. Vinson
  • 1,090
  • 6
  • 8
  • Hi, thank you for your help. But it looks like that mattermost doesn't support changing `app` port by configuring `docker-compose.yml`. Maybe I have to dive deeper to modify the files under `app` folder. – Brian Jul 11 '18 at 02:40
  • I'll take closer look at it – D. Vinson Jul 11 '18 at 02:48