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
dnsmasq
by declaring the*.local
hostnames (for example,subdomain1.example.local
) to a local server IP - Runs
nginx
and redirects the same local server to different Docker containers based on the hostname.- For example,
grafana.local
will 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-resolved
DNS server sincednsmasq
needs to bind to port 53 and install theresolvconf
package to keep resolving domains in Ubuntu.- To do this, see this answer
To run this:
- Create an
dsnsmasq.conf
file 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.conf
appropriately 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
.