Routing Traefik 2 to mutiple hosts outside hosted docker enviroment

so, little new here... maybe I don't know what I need to be asking.... but here goes...

I have mutiple containers running... all on different ports... redirecting their internal port (80->8080) example....

how do I configure mapping a host in my network... running another application:

Internet traffic ports 80/443 directed to 192.168.1.100
Container 1 runs on port 8080 on 192.168.1.100
Container 2 runs on port 8081 on 192.168.1.100
Container 3 runs on port 8082 on 192.168.1.100

Container 4 runs on port 8090 on 192.168.1.101
Container 5 runs on port 8091 on 192.168.1.101

I need :
8080 to resolve to app1.mydomain.com
8081 to resolve to app2...
8082 to resolve to app3...
8090 to resolve to app4...
8091 to resolve to app5...

I am not sure where I can make these changes, or what this specifically is called....

any help would be greatly appreciated.

I am hosting on cloudflare so....

thanks for any assistance anyone can provide.

Hey @MTY ,

what is the environment you are running in? Are 192.168.1.100 and 192.168.1.101 clustered in some way (Docker Swarm, Kubernetes)? Or are you running single (docker) hosts and just happen to have Traefik installed on one of them? This would make a difference here for the applications on the second host.

But let's start with the host Traefik is running on: Once Traefik is running there and you have a way of reaching your http entrypoint, you don't need the port publishing anymore.

What you do is labeling your services/containers with some Traefik specific labels to configure the proxying done by Traefik. The following example is for Docker:

services:
  myapp1
    image: ...
    labels:
      - traefik.enable=true
      - traefik.http.routers.myapp1.rule=Host(`myapp1.mydomain.com`)
      - traefik.http.routers.myapp1.entrypoints=websecure
      - traefik.http.services.myapp1.loadbalancer.server.port=80
...

In case your container only exposes one port the last label can be omitted.

The documentation on dynamic configuration really helps here: Docker - Traefik | Site | v2.4

In case your other host is clustered with your first host, this should now also work exactly the same way for applications running there.

In case there is no clustering in place, Traefik will not be able to read the labels of those containers, hence it will not be able to configure itself. In that case you need to manually define the routers and services. You can do this in the a dynamic configuration in file, for example. here's an example:

http:
  routers:
    myapp4:
      entrypoints:
        - websecure
      service: myapp4@file
      rule: Host(`myapp4.mydomain.com`)
  services:
    myapp4:
      loadBalancer:
        servers:
          - url: 192.168.1.101:8090

Be aware, that in this case you still need to publish the container port on the host machine!

Put this file on the path, that is configured in Traefik for the file-provider (File - Traefik | Site | v2.4)

And here's the docu on the file dynamic configuration: File - Traefik | Site | v2.4

Best,
razr

So, both .100 and .101 are running docker….

.102 is running a physical bare metal instance of Plex Media Server

:80 and :443 are port-forwarded to .100

:32400 – is port forwarded to .102

Example:

.100 is running a Wordpress instance and Traefik2

.101 is running an Axigen-Email server…

.102 is running a baremetal Plex Media Server – not in docker…

All are on physically different machines…

And (IMAP|SMTP|MAIL).mydomain.com need to go to .100

So Blog.mydomain.com needs to go to .101

And Plex.mydomain.com needs to head to .102

How do I get the plex (example) to use the .100 Traefik2 as the entry point….

Thank you for your assistance….

Ok, then for all applications running in docker on the same host Traefik is running you can use the labels as described above.

For Plex you can use the second approach I described above with the dynamic configuration from file:

http:
  routers:
    plex:
      entrypoints:
        - websecure
      service: plex@file
      rule: Host(`plex.mydomain.com`)
  services:
    plex:
      loadBalancer:
        servers:
          - url: 192.168.1.102:32400

Put this in a file in a directory on .100 and mount that directory to your Traefik container. Then configure the file provider for Traefik in the static config and add the path inside your container as the directory: File - Traefik | Site | v2.4

Make yourself familiar with the static and dynamic configuration. The documentation is actually pretty good there :slight_smile:

You can also have a look at the examples from one of my repositories to see how I redirected network traffic outside the Docker environment. Hope that helps.