Utilize 2 ips with traefik

Hello,

in the documentation there is a section about listening to a specific IP address such as "entrypoints.specificIPv4.address=192.168.2.7:8888", but unfortunately, that is not possible within docker because those IP addresses are not available inside the traefik container (obviously).

So, how can I use traefik for multiple IP addresses?

(The only other way how I was able to do that was the following:

...
    command:
      - "--entrypoints.95http.address=:80"
      - "--entrypoints.92http.address=:81"
    ports:
      - "1.1.1.1:80:80"
      - "2.2.2.2:80:81"
...

)

If you are only binding to the specific ip's then setting them on the ports section of a compose is appropriate.

I generally would not create two specific entrypoints but your use case may be very particular.

Well, I need to bind both ips to the same port externally. Let's say I have two website, one on each IP.
1.1.1.1 -> Website 1 running on port 80
2.2.2.2 -> Website 2 running on port 80

How would I reflect this in traefik if not with the way of two entrypoints how I did?
Because I need to seperate them within traefik somehow to tell them apart.

Also my biggest problem here is that I need to map 80 (host) to 81 (traefik docker) to 81 (traefik) to 80 (docker service utilizing traefik) which seems a bit inconvienient and causes issues.

I would be using a Host() rule. And just leave traefik bound on any/all interface on 80/443.

I think you are over complicating it. Why not like this:

version: "3.8"

services:
  traefik:
    image: "traefik:v2.2"
    command:
    - --entrypoints.web.address=:80
    - --providers.docker=true
    - --providers.docker.exposedbydefault=false
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./simple-static.yaml:/etc/traefik/traefik.yaml"
  site1:
    image: nginx
    labels:
      traefik.enable: "true"
      traefik.http.routers.site1.rule: Host(`site1.example.com`)
      traefik.http.routers.site1.entrypoints: web
  site1:
    image: nginx
    labels:
      traefik.enable: "true"
      traefik.http.routers.site2.rule: Host(`site2.example.com`)
      traefik.http.routers.site2.entrypoints: web

Ah, I forgot that this syntax would bind it to all ips, thank you very much, works flawlessly, but 2 questions remain for me:

  1. Any particular reason you would not use multiple endpoints? I mean aren't they designed for that?
  1. What exactly did you mean by "only binding to the specific ips"?

Generally I have two, that's it.

version: "3.8"

services:
  traefik:
    image: "traefik:v2.2"
    command:
    - --entrypoints.web.address=:80
    - --entrypoints.web.http.redirections.entryPoint.to=websecure
    - --entrypoints.web.http.redirections.entryPoint.scheme=https
    - --entrypoints.web.http.redirections.entrypoint.permanent=true
    - --entrypoints.websecure.address=:443
    - --entrypoints.websecure.http.tls=true
...
...
...

If the host has multiple ip's external and/or internal. And you only wanted traefik's ports published/bound to those ip's

In your snippet:

    ports:
      - "1.1.1.1:80:80"
      - "2.2.2.2:80:81"

Docker would only bind 1.1.1.1:80 and 2.2.2.2:80. Any other ip on the docker host would not respond on port 80. I don't think it is really common but it is there for people to use.

Ah, okay. Well, thank you again for helping out. My main "thinking error" was that I thought I need to somehow seperate the IP's from traefik but because traefik is working on application layer and not on the network layer anyway that was of course a mistake.