Skip to content

Instantly share code, notes, and snippets.

@ismailyenigul
Last active May 30, 2023 04:46
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ismailyenigul/867132f298664156068b6e85847c0dfe to your computer and use it in GitHub Desktop.
Save ismailyenigul/867132f298664156068b6e85847c0dfe to your computer and use it in GitHub Desktop.
docker labels for traefik reverse proxy multiple ports in a single container with different domain names
--label "traefik.enable=true" \
--label "traefik.protocol=http" \
--label "traefik.first.port=80" \
--label "traefik.first.frontend.rule=Host:web1.example.com" \
--label "traefik.second.port=8080" \
--label "traefik.second.frontend.rule=Host:web2.example.com" \
Above labels will allow us to forward web1.example.com to docker container port 80 and web2.example.com to same container's port 8080
Please note that this labels are valid for traefik v1. v2 has different labels
@williamdes
Copy link

williamdes commented Dec 1, 2020

version: "3"
services:
   traefik:
    image: traefik:v2.2
   # More config ...
  gophish:
    image: gophish/gophish
    volumes:
      - ${GOPHISH_DB_DIR}:/app/database
      - ${GOPHISH_STATIC_DIR}:/app/static/endpoint
      - ${GOPHISH_STATIC_DIR}:/opt/gophish/static/endpoint
    restart: on-failure:5
    dns_search: example.fr
    hostname: www.example.fr
    domainname: example.fr
    container_name: gophish
    networks:
      internal-server:
        aliases:
          - www.example.fr
    environment:
      - ADMIN_LISTEN_URL=0.0.0.0:3333
      - ADMIN_USE_TLS=false
      - PHISH_LISTEN_URL=0.0.0.0:888
      - PHISH_USE_TLS=false
      - GOPHISH_INITIAL_ADMIN_PASSWORD=public
      - DB_FILE_PATH=/app/database/gophish.db
    labels:
      traefik.enable: true
      traefik.docker.network: internal-server

      traefik.http.routers.www-router.rule: host(`www.example.fr`)
      traefik.http.routers.www-router.entrypoints: websecure
      traefik.http.routers.www-router.tls: "true"
      traefik.http.routers.www-router.tls.certresolver: "acmeresolver"
      traefik.http.routers.www-router.service: www
      # You can remove the next line, only custom config for me
      traefik.http.routers.www-router.middlewares: "deny-robots@file, clean-headers@file"

      traefik.http.routers.www-router-http.rule: host(`www.example.fr`)
      traefik.http.routers.www-router-http.entrypoints: web
      traefik.http.routers.www-router-http.service: www
      # You can remove the next line, only custom config for me
      traefik.http.routers.www-router-http.middlewares: "deny-robots@file, clean-headers@file"

      traefik.http.services.www.loadbalancer.server.port: 888

      traefik.http.routers.admin-router-http.rule: host(`gophish-admin.example.fr`)
      traefik.http.routers.admin-router-http.entrypoints: web
      traefik.http.routers.admin-router-http.service: administration
     # You can remove the next line, only custom config for me
      traefik.http.routers.admin-router-http.middlewares: "deny-robots@file, clean-headers@file"

      traefik.http.routers.admin-router.rule: host(`gophish-admin.example.fr`)
      traefik.http.routers.admin-router.entrypoints: websecure
      traefik.http.routers.admin-router.tls: "true"
      traefik.http.routers.admin-router.tls.certresolver: "acmeresolver"
      traefik.http.routers.admin-router.service: administration
      # You can remove the next line, only custom config for me
      traefik.http.routers.admin-router.middlewares: "deny-robots@file, clean-headers@file"

      traefik.http.services.administration.loadbalancer.server.port: 3333

traefik.yml

If you see on the dashboard a router Traefik did create itself.

providers:
    docker:
        exposedbydefault: false
        defaultRule: "HostRegexp(`{{ index .Labels \"com.docker.compose.service\"}}-defaultRule.localhost`)"

ACME resolver by http (traefik.yml)

certificatesResolvers:
    acmeresolver:
        acme:
            email: tech@example.fr
            storage: acme.json
            httpChallenge:
                entryPoint: web

@MartyLake
Copy link

MartyLake commented Oct 24, 2021

Thank you very much Sir for saving my sunday night hacking plan !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment