First of all I\'m sorry if I\'m not using the right terms to ask this question, but I\'m not up to the terminology in place.
I have traefik running in a docker container
I've fiddled around and found the answer.
In traefik.toml
add:
################################################################
# File configuration backend
################################################################
# Enable file configuration backend
# Optional
[file]
filename = "servers.toml"
# Enable watch file changes
watch = true
In docker-compose.yml
change the volumes:
to:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ${SERVER_DIR}/AppData/traefik:/etc/traefik/
- ${PWD}/acme.json:/acme.json
- ${PWD}/traefik.toml:/etc/traefik/traefik.toml
- ${PWD}/servers.toml:/servers.toml
Add file servers.toml
:
loglevel = "ERROR"
[backends]
[backends.nasweb]
[backends.nasweb.servers.nasweb]
url = "http://192.168.1.11:8080"
[frontends]
[frontends.domain]
backend = "nasweb"
[frontends.domain.routes.domain]
rule = "Host:www.myserver.com"
With the new Traefik (v.2) you need to use a combination of labels and an external file, you can find below my working example.
In your docker compose you need to add the comands to define the external file and enable the provider
- "--providers.file=true"
- "--providers.file.filename=/etc/traefik/rules.toml"
Into your file (rules.toml) the routing to foward to your external service (be aware of the syntax, use the char to define the host ( ` ) )
example :
Docker-compose:
traefik:
image: "traefik:v2.0.0"
container_name: "traefik"
restart: always
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.myhttpchallenge.acme.httpchallenge=true"
- "--certificatesresolvers.myhttpchallenge.acme.httpchallenge.entrypoint=web"
- "--certificatesresolvers.myhttpchallenge.acme.email=xx@xx.com"
- "--providers.file=true"
- "--providers.file.filename=/etc/traefik/rules.toml"
- "--providers.docker=true"
- "--providers.file.watch=true"
ports:
- "80:80"
- "8080:8080"
- "443:443"
networks:
- proxy
environment:
- CF_API_EMAIL="xx"
- CF_API_KEY="xx"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./traefik/rules.toml:/etc/traefik/rules.toml"
Rules.toml
[http.routers]
# Define a connection between requests and services
[http.routers.nasweb]
rule = "Host(`nas.xxxx.com`)"
entrypoints = ["websecure"]
service = "nas"
[http.routers.nasweb.tls]
certResolver = "myhttpchallenge"
[http.services]
# Define how to reach an existing service on our infrastructure
[http.services.nas.loadBalancer]
[[http.services.nas.loadBalancer.servers]]
url = "http://192.168.0.165:80"