Hi everyone,
i have an issue with traefik when i want to use my domain inside WSL..
Some details about my environment :
my host system is windows (11)
i have WSL2 with ubuntu (20.04) inside
and docker is installed in ubuntu
$ docker version
Client: Docker Engine - Community
Version: 26.1.3
...
Here an example of traefik configuration :
services:
traefik:
image: traefik:latest
restart: no
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ${PROJECT_PATH}/traefik/traefik.yml:/etc/traefik/traefik.yml
- ${PROJECT_PATH}/traefik/services.yml:/etc/traefik/services.yml
- ${PROJECT_PATH}/traefik/certs/:/etc/certs/
labels:
- "traefik.enable=true"
- "traefik.http.routers.dashboard.rule=Host(`test-traefik.dev.localhost`)"
- "traefik.http.routers.dashboard.entrypoints=http,https"
- "traefik.http.routers.dashboard.service=api@internal"
on windows, if i try to access to http://test-traefik.dev.localhost/dashboard/#/ with any browser all is ok !
on ubuntu(wsl), if i try:
$ curl http://test-traefik.dev.localhost
curl: (6) Could not resolve host: test-traefik.dev.localhost
Globally, all domains defined with traefik is not available under WSL.
however i confirm that ports are open and listen
docker-pr 253684 root 4u IPv4 1671203 0t0 TCP *:443 (LISTEN)
docker-pr 253690 root 4u IPv6 1671210 0t0 TCP *:443 (LISTEN)
docker-pr 253709 root 4u IPv4 1672237 0t0 TCP *:80 (LISTEN)
docker-pr 253726 root 4u IPv6 1668894 0t0 TCP *:80 (LISTEN)
thanks !
Where did you define the domain to resolve to the IP?
Some browser will resolve any domain with localhost
automatically to 127.0.0.1
, but I don't think curl
will do that.
Hi @bluepuma77 ,
thanks for you answer ! Good point to see !
on windows, my hosts file is fully commented, so probably the domain resolution come from traefik directly no !? for me, traefik listen port 80, recognize the domain and say : "ok it's for me i know the domain in your request and i can return a response...":
...
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
on WSL:
$ cat /etc/hosts
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1 localhost
127.0.1.1 MY_SUPER_ID
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
Hi @Hraesvelg
The following are personal opinions, then you can use the local domain to serve the local service in wsl and outside windows.
- Set the dns resolve in wsl ubuntu:
First you need to modify /etc/resolv.conf in Ubuntu
And add 127.0.0.1 localhost, but this method may be reset when wsl restarts;
It is recommended to modify /etc/systemd/resolved.conf
And add [Nameserver] DNS=127.0.0.1
- Check the network card ip is static. if not your should manual setting.
modify /etc/netplan/xxx.yaml
- Deploye the pihole, and setting local dns(pihole web admin->local dns->dns records), give a domain name(ex: mydomain.local) & wsl ubuntu ip address, it would be like this(mydomain.local<->xxx.xxx.xxx.xxx)
★use docker network card same with traefik
★if you want use traefik routers to your http/https, then in .yaml you should not setting expose the port number or port mapping, traefik would auto redirect to them.
add following labels in pihole docker compose, please check you have already set tls cert in cloudflare and set the cloudflare token in pihole.
labels:
- traefik.enable=true
- traefik.http.routers.pihole.entrypoints=https
- traefik.http.routers.pihole.rule=Host(
pihole.mydomain.local
)
- traefik.http.routers.pihole.tls=true
- traefik.http.routers.pihole.tls.certresolver=cloudflare
- traefik.http.services.pihole.loadbalancer.server.port=80 # the port number is inside container used port not the outside host used port
- In wsl cmd, use nslooup mydomain.local, check it can resolve mydomain.local
- Modify windows network cards setting, Lan or wifi whatever the main one(dns server add wsl ubuntu ip), for pihole resolve the local dns and outside dns.
★This step is key, if you setting up networks card dns in windows, then you can pass to modify windows /etc/host to resolve the local services.
- In pihole web admin->local dns->cname records add traefik-dashboard.mydomain.local<->mydomain.local, and don'ts forget add pihole, pihole.mydomain.local<->mydomain.local
- Again, in wsl cmd and windows cmd use nslookup, check traefik-dashboard.mydomain.local can resolve
- In windows open the web browser, type traefik-dashboard.mydomain.local, check it's works; or use curl https://traefik-dashboard.mydomain.local
Hope the above steps are helpful to you, have good day.