This has a Docker Compose that runs dnsmasq (DNS server) + nginx (reverse proxy) to redirect hostnames to specific Docker containers in a local network.
- Runs
dnsmasqby declaring the*.localhostnames (for example,subdomain1.example.local) to a local server IP - Runs
nginxand redirects the same local server to different Docker containers based on the hostname.- For example,
grafana.localwill proxy tohttp://host.docker.internal:3000, where Grafana is running
- For example,
You will need:
- Docker
- If you are running this in Ubuntu you will need to disable the
systemd-resolvedDNS server sincednsmasqneeds to bind to port 53 and install theresolvconfpackage to keep resolving domains in Ubuntu.- To do this, see this answer
To run this:
- Create an
dsnsmasq.conffile like this.
address=/local/<your server IP>
no-resolv
server=8.8.8.8
server=8.8.4.4
# this should only be enabled for troubleshooting
# since it creates too many logs
# log-queries
-
Configure the
nginx.confappropriately to your needs -
Run Docker Compose
docker compose up -d-
Before changing the DNS server in your router manually change the DNS server in one of your devices to test to avoid breaking the devices in your network
-
If things go well change the DNS server in your router to use the DNS from
dnsmasq.