Traefik routes traffic that matches the hostname of a Docker service's
traefik.frontend.rule
label. However, for applications running on your host
machine (curl, wget, the browser, etc.) to be able to know where to find the
host you need to configure your DNS to resolve all hostnames ending on
".localhost" to your local IP address.
On Ubuntu 18.04 no action is required, because systemd-resolved already resolves hostnames ending on ".localhost" to 127.0.0.1 and ::1.
If for some reason resolving is not working on Ubuntu, make sure that the
symlink /etc/resolv.conf
is pointing to /run/systemd/resolve/stub-resolv.conf
:
ll /etc/resolv.conf
If this doesn't point to /run/systemd/resolve/stub-resolv.conf
, overwrite the
symbolic link:
sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
On macOS the same can be achieved by installing dnsmasq and configuring it to route all traffic for ".localhost" to 127.0.0.1:
brew install dnsmasq
mkdir -pv $(brew --prefix)/etc/
echo 'address=/.localhost/127.0.0.1' >> $(brew --prefix)/etc/dnsmasq.conf
echo 'port=53' >> $(brew --prefix)/etc/dnsmasq.conf
sudo brew services start dnsmasq
sudo mkdir -v /etc/resolver
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/localhost'
ping dashboard.leviy.localhost