# How to manage multiple ports exposed on port 80 with docker?

**URL:** <https://community.traefik.io/t/how-to-manage-multiple-ports-exposed-on-port-80-with-docker/1782>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [September 21, 2019, 5:42pm UTC](https://community.traefik.io/t/how-to-manage-multiple-ports-exposed-on-port-80-with-docker/1782 "2019-09-21T17:42:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![thiloilg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/thiloilg/32/723_2.png) [@thiloilg](https://community.traefik.io/u/thiloilg)\
**Post date:** [September 21, 2019, 5:42pm UTC](https://community.traefik.io/t/how-to-manage-multiple-ports-exposed-on-port-80-with-docker/1782/1 "2019-09-21T17:42:40Z")

</div>

I have the following setup:

```auto
version: '3'

services:
  traefik:
    image: traefik:v2.0
    container_name: traefik
    ports:
      - 80:80
    command:
      - --api.debug=true
      - --api.insecure=true
      - --providers.docker=true
      - --entrypoints.web.address=:80
      - --providers.docker.exposedByDefault=true
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      - traefik.http.routers.traefik.service=api@internal
      - traefik.http.routers.traefik.rule=Host(`monitor.domain.org`)
      - traefik.http.routers.traefik.entrypoints=web
    networks:
      - web
  db:
    image: registry.domain.com/repo/db:latest
    container_name: db
    restart: always
    networks:
      - internal
  api:
    image: registry.domain.com/repo/api:latest
    container_name: api
    ports:
      - 80:3001
    volumes:
      - /root/rsa.pem:/root/certs/rsa.pem
      - /root/rsa_pub.pem:/root/certs/rsa_pub.pem
    restart: always
    depends_on:
      - db
    environment:
      - MAIL_ADDRESS=${MAIL_ADDRESS}
      - MAIL_PASSWORD=${MAIL_PASSWORD}
      - MAIL_HOST=${MAIL_HOST}
    labels:
      - traefik.http.routers.api.rule=Host(`api.domain.org`)
      - traefik.http.routers.api.entrypoints=web
    networks:
      - internal
      - web
  app:
    image: registry.domain.com/repo/app:latest
    container_name: app
    restart: always
    depends_on:
      - api
      - db
    labels:
      - traefik.http.routers.app.rule=Host(`domain.org`,`www.domain.org`)
      - traefik.http.routers.app.entrypoints=web
    networks:
      - web

networks:
  web:
    external: true
  internal:
    external: false

```

Obviously I get an error from docker saying `Bind for 0.0.0.0:80 failed: port is already allocated`. Either exposing the `port 80` of the `traefik` service or the `api` service separately works perfectly. If I do not expose the `port 80` on those both services it does not work for both of them. The `app` service which runs on Nginx works without exposing `port 80` seamlessly. How can I make the `api` and `traefik` service both run together on `port 80`?

Regards,

Thilo

---

<div class="post-metadata">

**Author:** ![ldez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/ldez/32/5_2.png) [@ldez](https://community.traefik.io/u/ldez)\
**Post date:** [September 21, 2019, 6:05pm UTC](https://community.traefik.io/t/how-to-manage-multiple-ports-exposed-on-port-80-with-docker/1782/2 "2019-09-21T18:05:53Z")

</div>

Hello,

you don't need to expose the port of your service named `api`, you just need to define the port of the related service: `traefik.http.services.<name>.loadbalancer.server.port=<port number>`

```auto
version: '3'

services:
  traefik:
    image: traefik:v2.0
    container_name: traefik
    ports:
      - 80:80
    command:
      - --api=true
      - --providers.docker=true
      - --entrypoints.web.address=:80
      - --providers.docker.exposedByDefault=true
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      - traefik.http.routers.traefik.service=api@internal
      - traefik.http.routers.traefik.rule=Host(`monitor.domain.org`)
      - traefik.http.routers.traefik.entrypoints=web
    networks:
      - web

  db:
    image: registry.domain.com/repo/db:latest
    container_name: db
    restart: always
    networks:
      - internal

  api:
    image: registry.domain.com/repo/api:latest
    container_name: api
    volumes:
      - /root/rsa.pem:/root/certs/rsa.pem
      - /root/rsa_pub.pem:/root/certs/rsa_pub.pem
    restart: always
    depends_on:
      - db
    environment:
      - MAIL_ADDRESS=${MAIL_ADDRESS}
      - MAIL_PASSWORD=${MAIL_PASSWORD}
      - MAIL_HOST=${MAIL_HOST}
    labels:
      - traefik.http.routers.api.rule=Host(`api.domain.org`)
      - traefik.http.routers.api.entrypoints=web
      - traefik.http.services.api.loadbalancer.server.port=3001
    networks:
      - internal
      - web

  app:
    image: registry.domain.com/repo/app:latest
    container_name: app
    restart: always
    depends_on:
      - api
      - db
    labels:
      - traefik.http.routers.app.rule=Host(`domain.org`,`www.domain.org`)
      - traefik.http.routers.app.entrypoints=web
    networks:
      - web

networks:
  web:
    external: true
  internal:
    external: false

```

---

<div class="post-metadata">

**Author:** ![thiloilg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/thiloilg/32/723_2.png) [@thiloilg](https://community.traefik.io/u/thiloilg)\
**Post date:** [September 21, 2019, 6:36pm UTC](https://community.traefik.io/t/how-to-manage-multiple-ports-exposed-on-port-80-with-docker/1782/3 "2019-09-21T18:36:19Z")

</div>

@ldez Thank you for your effort! I dont know why but this does not seam to work in my case. I am also wondering why there is a difference between the `app` service and the `api`. The app is Nginx and the api is a node container. Here is my repo:

[https://gitlab.thiloilg.com/repo/blicc/blob/master/docker-compose.yml](https://gitlab.thiloilg.com/repo/blicc/blob/master/docker-compose.yml)

The weird thing is when I expose `port 80` separately for each service it works perfectly.

---

<div class="post-metadata">

**Author:** ![ldez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/ldez/32/5_2.png) [@ldez](https://community.traefik.io/u/ldez)\
**Post date:** [September 21, 2019, 6:45pm UTC](https://community.traefik.io/t/how-to-manage-multiple-ports-exposed-on-port-80-with-docker/1782/4 "2019-09-21T18:45:43Z")

</div>

I think your problem is related to your network configuration.

`app` uses `web`.  
`api` uses `web` and `internal`

So try to set the same network for all your containers or use the label `traefik.docker.network`

[https://docs.traefik.io/v2.0/providers/docker/#traefikdockernetwork](https://docs.traefik.io/v2.0/providers/docker/#traefikdockernetwork)

* * *

Also:

- remove `--api.debug=true` because that don't do what do you think: [https://docs.traefik.io/v2.0/operations/api/#debug](https://docs.traefik.io/v2.0/operations/api/#debug)
- replace `- --api.insecure=true` by `- --api=true`

---

<div class="post-metadata">

**Author:** ![thiloilg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/thiloilg/32/723_2.png) [@thiloilg](https://community.traefik.io/u/thiloilg)\
**Post date:** [September 21, 2019, 7:12pm UTC](https://community.traefik.io/t/how-to-manage-multiple-ports-exposed-on-port-80-with-docker/1782/5 "2019-09-21T19:12:44Z")

</div>

@ldez Yes I think you are right this is probably my network setup. So I tried to add the label `- traefik.docker.network=web` to the api to tell traefik that it should use this network instead of the internal but this does not seam to work. What am I doing wrong here?

I probably should just use one network and use Traefik for securing the database. Is there any boilerplate with a Traefik docker compose setup I can take a look at?

---

<div class="post-metadata">

**Author:** ![zespri](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/zespri/32/310_2.png) [@zespri](https://community.traefik.io/u/zespri)\
**Post date:** [September 23, 2019, 3:46am UTC](https://community.traefik.io/t/how-to-manage-multiple-ports-exposed-on-port-80-with-docker/1782/6 "2019-09-23T03:46:24Z")

</div>

There is an example in the documentation here: [https://docs.traefik.io/user-guides/docker-compose/basic-example/](https://docs.traefik.io/user-guides/docker-compose/basic-example/)
