Trafik reverse-proxy with docker-backend - configure interface rules in the traefik configuration file, and not through the container label

To use traefik as a reverse proxy in front of the Docker container, whose dynamic IP address may change over time, traefik appears from the backend docker . All the examples I could find to configure this follow the same pattern:

First, run traefik in mode dockerwithout an additional configuration file, activate network network mode (it is not necessary that traefik can see all Docker networks on the host, if necessary) and mount the UNIX Docker socket so that traefik can listen to start and stop the container.

docker run --rm -p 80:80 --net=host --name traefik-reverse-proxy -v /dev/null/traefik.toml:/etc/traefik/traefik.toml -v /var/run/docker.sock:/var/run/docker.sock traefik --docker --loglevel debug

Then run another container and set at least the following labels :

  • traefik.backend: "some-backend-name"
  • traefik.frontend.rule: "Host: localhost; Method: GET" (or whatever you do)
  • traefik.port: 80 (or any port that the container exposes internally)

Example:

docker run --rm --name nginx -l traefik.backend="some-backend-name" -l traefik.frontend.rule="Host: localhost; Method: GET" -l traefik.port="80 nginx

Then, after executing curl localhost, in the container logs traefikyou can see that he took the request and sent it to the NGINX container.

... , (, forward Host: some.host.name xxx) ( , , , ..). , traefik.

-? traefik.frontend.rule nginx traefik:

[frontends]
  [frontends.frontend1]
  backend = "some-backend-name"
    [frontends.frontend1.routes.test_1]
    rule = "Host: localhost; Method: GET"

, traefik :

docker run --rm -p 80:80 --net=host --name traefik-reverse-proxy -v $PWD/traefik.toml:/etc/traefik/traefik.toml -v /var/run/docker.sock:/var/run/docker.sock traefik --docker --loglevel debug

, , frontend - nginx. curl localhost 404 / Not found.

+4
2

watch rule.toml, .

etcd zookeeper. etcd traefik etcd.

+1

, , . config (debug = true) , traefik , .

, , , .

, (, rules.toml ) watch = true . , , , .

, , , .

0

Source: https://habr.com/ru/post/1671131/


All Articles