Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Which traefik docker labels for pointing to an additional webserver? #3140

Open
elindgren opened this issue Jan 29, 2024 · 3 comments
Open

Comments

@elindgren
Copy link

Hi! I want to use the included traefik reverse proxy to also handle requests to an additional webserver I'm running in a docker container on the same server as all the other services. I followed this section of the docs where, if I understand correctly, I can add my service to traefik simply by specifying the correct labels for my docker service. See the configuration I use in my docker-compose.yaml below.

My service can join the traefik docker network just fine, but when I access https://subdomain.myserver.org I get a 404 not found. I suspect I've misconfigured the traefik labels, specifically with regards to the traefik router name (it's probably not myrouter as I've used 😆), but I don't know what it should be. Anyone that can help a struggling hobbyist out? 😅

docker-compose.yaml

version: "3"
services:
  webserver:
    image: webserver:latest
    restart: always
    ports:
      - "4173:4173"
    build:
       context: .
       labels:
         - traefik.http.routers.myrouter.rule=Host(`subdomain.myserver.org`) # enable trafik reverse proxy
         - traefik.http.routers.myrouter.tls=true              # enable tls via reverse proxy
         # Tell Traefik to use the port 4173 to connect to `my-container`
         - traefik.http.services.my-service.loadbalancer.server.port=4173

networks:
  default:
    name: traefik
    external: true  # requires the traefik network from docker-ansible-deploy to have been created

@Virkkunen
Copy link

Virkkunen commented Feb 9, 2024

I might be wrong, but I've used the following labels and my other containers are successfully integrated in Traefik:

labels:
      - traefik.enable=true
      - traefik.docker.network=traefik
      - traefik.http.routers.[NAME].entrypoints=web-secure
      - traefik.http.routers.[NAME].service=[NAME]
      - traefik.http.routers.[NAME].rule=[RULE]
      - traefik.http.routers.[NAME].tls=true
      - traefik.http.routers.[NAME].tls.certResolver=default
      - traefik.http.routers.[NAME].tls.domains[0]=[DOMAIN]
      - traefik.http.routers.[NAME].tls.domains[0].sans=[SUBDOMAIN]
      - traefik.http.services.[NAME].loadbalancer.server.port=[CONTAINER PORT]

Also adding the networks config under the compose services:

networks:
      - traefik

and under the compose networks:

networks:
  traefik:
    external: true

@elindgren
Copy link
Author

I might be wrong, but I've used the following labels and my other containers are successfully integrated in Traefik:

labels:
      - traefik.enable=true
      - traefik.docker.network=traefik
      - traefik.http.routers.[NAME].entrypoints=web-secure
      - traefik.http.routers.[NAME].service=[NAME]
      - traefik.http.routers.[NAME].rule=[RULE]
      - traefik.http.routers.[NAME].tls=true
      - traefik.http.routers.[NAME].tls.certResolver=default
      - traefik.http.routers.[NAME].tls.domains[0]=[DOMAIN]
      - traefik.http.routers.[NAME].tls.domains[0].sans=[SUBDOMAIN]
      - traefik.http.services.[NAME].loadbalancer.server.port=[CONTAINER PORT]

Also adding the networks config under the compose services:

networks:
      - traefik

and under the compose networks:

networks:
  traefik:
    external: true

Nice, thanks! I tried it but there is still something that doesn't seem to be quite correctly configured. What is [NAME], is that just name of the docker service (webserver in my example yaml file)? What is RULE?

@Virkkunen
Copy link

Yes, [NAME] is the container/service name, webserver in your case. [RULE] should be your routing rule, according to https://doc.traefik.io/traefik/routing/routers/#rule_1, like Host(`subdomain.myserver.org`)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants