Search code examples
dockerdocker-composeportsubdomaintraefik

How to bind multi (sub)domain to one container in docker with different ports in traefik


I have three subdomain api.mydomain.com, dl.mydomain.com and blog.mydomain.com and i have one container with 3 port (5000,5001,5002) ...

Now i like to bind api.mydomain.com to port 5000, dl.mydomain.com to port 5001 and blog.mydomain.com to port 5002.

note: I use docker-compose in one to one bind i use blowe code

 my_container:
    container_name: my_container
    restart: always
    build: .
    labels:
      - "traefik.backend=my_container"
      - "traefik.enable=true"
      - "traefik.docker.network=web"
      - "traefik.frontend.rule=Host:api.mydomain.com"

Solution

  • You should be able to achieve this with segments: https://docs.traefik.io/configuration/backends/docker/#on-containers-with-multiple-ports-segment-labels

    traefik.<segment_name>.frontend.rule=EXP
    traefik.<segment_name>.port=PORT
    [...]