3.7 KiB
Local DNS Services with Docker
This project provides a local development infrastructure with automatic DNS resolution for custom domains (e.g., .mikan or .local) and valid HTTPS certificates.
Features
- Automatic DNS resolution for
*.yourdomainand*.yourdomain.local - Valid HTTPS certificates for local domains using
mkcert - Easy service deployment with
VIRTUAL_HOSTenvironment variables - Ready for future expansion: public domains, Let's Encrypt, Tailscale
- Single-command service creation
Requirements
- Docker and Docker Compose
mkcertinstalled on the host system
Quick Start
-
Clone this repository and enter the directory:
git clone <repository-url> local-dns cd local-dns -
Initialize the project:
./scripts/00-init.shThis creates a
.envfile from.env.exampleand sets up the directory structure. -
Generate TLS certificates:
./scripts/01-generate-cert.shThis creates trusted certificates for your local domain.
-
Start the core infrastructure:
docker compose up -d -
Add your first service (example: Gitea on port 3000):
./scripts/add-service.sh gitea 3000Then edit
services/gitea/docker-compose.ymlto set the correct image and volumes. -
Start the new service:
docker compose -f docker-compose.yml -f services/gitea/docker-compose.yml up -d -
Visit
https://gitea.yourdomainin your browser (replaceyourdomainwith your configured domain).
Configuration
Edit the .env file to customize your setup:
LOCAL_DOMAIN: Your local domain suffix (default:mikan)PUBLIC_DOMAIN: Optional public domain for Let's Encrypt certificatesLETSENCRYPT_EMAIL: Email for Let's Encrypt notifications- Network settings (
NGINX_IP,DNSMASQ_IP, etc.)
After changing .env, re-run the initialization and certificate scripts.
DNS Setup
Linux/macOS
Use the included dnsmasq service for automatic DNS resolution:
docker compose -f docker-compose.yml -f docker-compose.dnsmasq.yml up -d
Then configure your system to use 10.0.0.2 as the primary DNS server.
Windows (WSL2)
Windows reserves port 53, so dnsmasq cannot run on the host. Instead:
- Work inside WSL2
- Manually add entries to the Windows hosts file:
# Run PowerShell as Administrator Add-Content -Path "C:\Windows\System32\drivers\etc\hosts" -Value "127.0.0.1 gitea.mikan" Add-Content -Path "C:\Windows\System32\drivers\etc\hosts" -Value "127.0.0.1 gitea.mikan.local"
Certificate Trust
After running ./scripts/01-generate-cert.sh, install the root certificate on your devices:
- Linux: Depends on distribution (usually via
update-ca-certificates) - macOS:
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ca/rootCA.pem - Windows:
- Copy
ca/rootCA.pemto Windows - Open
certmgr.msc - Import into "Trusted Root Certification Authorities"
- Copy
Adding Public Domain Support
To enable Let's Encrypt certificates for a public domain:
-
Set in
.env:PUBLIC_DOMAIN=yourdomain.com LETSENCRYPT_EMAIL=you@yourdomain.com -
Re-run initialization:
./scripts/00-init.sh ./scripts/01-generate-cert.sh -
New services will automatically request Let's Encrypt certificates for the public domain.
Service Management
- Add a service:
./scripts/add-service.sh <name> <port> - Start all:
docker compose up -d - Start with dnsmasq:
docker compose -f docker-compose.yml -f docker-compose.dnsmasq.yml up -d - Stop all:
docker compose down
All service data is stored in the services/ directory and persists between restarts.