# Multiple docker-compose Treafik instances

**URL:** <https://community.traefik.io/t/multiple-docker-compose-treafik-instances/11299>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [July 25, 2021, 7:11pm UTC](https://community.traefik.io/t/multiple-docker-compose-treafik-instances/11299 "2021-07-25T19:11:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![emilpaw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/emilpaw/32/4049_2.png) [@emilpaw](https://community.traefik.io/u/emilpaw)\
**Post date:** [July 25, 2021, 7:11pm UTC](https://community.traefik.io/t/multiple-docker-compose-treafik-instances/11299/1 "2021-07-25T19:11:37Z")

</div>

Hi,  
my goal is to run multiple instances of a docker-compose file with different entrypoint ports. I only want to expose this one port which serves both my backend and frontend.

For this I created following docker-compose.yml:

```auto
version: '3.8'

services:
  reverse-proxy:
    # The official v2 Traefik docker image
    image: traefik:v2.4
    # Enables the web UI and tells Traefik to listen to docker
    command:
      # Traefik will listen on port 8080 by default for API request.
      - '--api.insecure=true'
      # Enabling docker provider
      - '--providers.docker'
      # Do not expose containers unless explicitly told so
      - '--providers.docker.exposedbydefault=false'
      - '--entryPoints.${PORT}-web.address=:${PORT}'
    ports:
      # The HTTP port
      - ${PORT}:${PORT}
      # The Web UI (enabled by --api.insecure=true)
      # - '8082:8080'
    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock

  postgres:
    image: postgres:13.2
    environment:
      - POSTGRES_USER=oip
      - POSTGRES_PASSWORD=
      - POSTGRES_HOST_AUTH_METHOD=trust

  jhipster:
    build: ./jhipster
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/backend
    # ports:
    # - 8080:8080
    depends_on:
      - postgres
    labels:
      - 'traefik.enable=true'
      - 'traefik.http.routers.port-${PORT}-jhipster.rule=PathPrefix(`/api`)'
      - 'traefik.http.routers.port-${PORT}-jhipster.entrypoints=${PORT}-web'

  frontend:
    build: ./frontend
    # ports:
    # - 3000:3000
    depends_on:
      - jhipster
    labels:
      - 'traefik.enable=true'
      - 'traefik.http.routers.port-${PORT}-frontend.rule=PathPrefix(`/`)'
      - 'traefik.http.routers.port-${PORT}-frontend.entrypoints=${PORT}-web'

```

I run an instance like this:

```auto
PORT=50777 COMPOSE_PROJECT_NAME=PRO777 docker-compose up

```

To get multiple instances of this docker compose to run I had to parameterize some of the service names so they don't clash within traefik. Didn't find a better way to get this to start.

It sort of works but the instances show following errors: `reverse-proxy_1 | time="2021-07-25T18:46:02Z" level=error msg="entryPoint \"50777-web\" doesn't exist" routerName=port-50777-jhipster@docker entryPointName=50777-web`  
And also in the dashboard always the services of other instances are shown as failed.

Is there a way to isolate the the traefik instances? Like one traefik per docker-compose which does not know anything about the other running ones?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [July 28, 2021, 1:51pm UTC](https://community.traefik.io/t/multiple-docker-compose-treafik-instances/11299/2 "2021-07-28T13:51:40Z")

</div>

You will be interested in [constraints](https://doc.traefik.io/traefik/providers/docker/#constraints)

Traefik will filter to those containers that match the contraint, that should eliminate the need to parametize the service names too.

As to why your entrypoint does not exist I would start by inspecting the container and see what is there for the command section.

---

<div class="post-metadata">

**Author:** ![emilpaw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/emilpaw/32/4049_2.png) [@emilpaw](https://community.traefik.io/u/emilpaw)\
**Post date:** [July 28, 2021, 7:46pm UTC](https://community.traefik.io/t/multiple-docker-compose-treafik-instances/11299/3 "2021-07-28T19:46:13Z")

</div>

> [@cakiwi](#):
>
> You will be interested in [constraints](https://doc.traefik.io/traefik/providers/docker/#constraints)

Thanks. This looks like what I need, the docs about that feature are pretty short though. I'll try to figure it out.

> [@cakiwi](#):
>
> As to why your entrypoint does not exist I would start by inspecting the container and see what is there for the command section.

Not sure if I explained my error correctly. For the next screenshots I started the docker-compose two times, once with the port 50666 and once with 50777 and also changed the Web UI port nubmers so that I can view both at the same time.  
This is how the view of the instance with port 50666 looks:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/4/4f2b5ed6721bebc5fd8a01ff0dea5a05280463a8.png)

This is the Web UI of the one with port 50777:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/5/5f515e389f28c42f4241995c26a9ccaa218b3ca0.png)

What "command section" do you mean exactly?

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [July 28, 2021, 9:18pm UTC](https://community.traefik.io/t/multiple-docker-compose-treafik-instances/11299/4 "2021-07-28T21:18:52Z")

</div>

> [@emilpaw](#):
>
> What "command section" do you mean exactly?

I was interested in your entrypoint error, but having the two running on the same host without a constraint, that make sense that that error appears.

> [@emilpaw](#):
>
> Thanks. This looks like what I need, the docs about that feature are pretty short though. I'll try to figure it out.

Let us know how you progress. I can put together an example if you need one.

---

<div class="post-metadata">

**Author:** ![emilpaw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/emilpaw/32/4049_2.png) [@emilpaw](https://community.traefik.io/u/emilpaw)\
**Post date:** [August 10, 2021, 8:47am UTC](https://community.traefik.io/t/multiple-docker-compose-treafik-instances/11299/5 "2021-08-10T08:47:50Z")

</div>

Thanks again @cakiwi for the hint. I got it to work. For future reference, this is the working config using constrains:

```auto
services:
  reverse-proxy:
    # The official v2 Traefik docker image
    image: traefik:v2.4
    # Enables the web UI and tells Traefik to listen to docker
    command:
      # Enabling docker provider
      - '--providers.docker'
      # Do not expose containers unless explicitly told so
      - '--providers.docker.exposedbydefault=false'
      - '--entryPoints.${PORT}-web.address=:${PORT}'
      - '--providers.docker.constraints=Label(`custom.label`,`${COMPOSE_PROJECT_NAME}`)'
    ports:
      # The HTTP port
      - ${PORT}:${PORT}
    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock

  postgres:
    image: postgres:13.2
    environment:
      - POSTGRES_USER=oip
      - POSTGRES_PASSWORD=
      - POSTGRES_HOST_AUTH_METHOD=trust
    labels:
      - 'custom.label=${COMPOSE_PROJECT_NAME}'

  jhipster:
    build: ./jhipster
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/backend
    depends_on:
      - postgres
    labels:
      - 'traefik.enable=true'
      - 'traefik.http.routers.jhipster.rule=PathPrefix(`/api`)'
      - 'custom.label=${COMPOSE_PROJECT_NAME}'

  frontend:
    build: ./frontend
    depends_on:
      - jhipster
    labels:
      - 'traefik.enable=true'
      - 'traefik.http.routers.frontend.rule=PathPrefix(`/`)'
      - 'custom.label=${COMPOSE_PROJECT_NAME}'

```
