mirror of
https://github.com/basnijholt/compose-farm.git
synced 2026-02-03 06:03:25 +00:00
examples: Add CoreDNS for *.local domain resolution (#155)
* examples: Add CoreDNS for *.local domain resolution Adds a CoreDNS example that resolves *.local to the Traefik host, making the .local routes in all examples work out of the box. Also removes the redundant Multi-Container Stacks section from README since paperless-ngx already demonstrates this pattern. * examples: Add coredns .env file
This commit is contained in:
@@ -7,6 +7,7 @@ Real-world examples demonstrating compose-farm patterns for multi-host Docker de
|
|||||||
| Stack | Type | Demonstrates |
|
| Stack | Type | Demonstrates |
|
||||||
|---------|------|--------------|
|
|---------|------|--------------|
|
||||||
| [traefik](traefik/) | Infrastructure | Reverse proxy, Let's Encrypt, file-provider |
|
| [traefik](traefik/) | Infrastructure | Reverse proxy, Let's Encrypt, file-provider |
|
||||||
|
| [coredns](coredns/) | Infrastructure | Wildcard DNS for `*.local` domains |
|
||||||
| [mealie](mealie/) | Single container | Traefik labels, resource limits, environment vars |
|
| [mealie](mealie/) | Single container | Traefik labels, resource limits, environment vars |
|
||||||
| [uptime-kuma](uptime-kuma/) | Single container | Docker socket, user mapping, custom DNS |
|
| [uptime-kuma](uptime-kuma/) | Single container | Docker socket, user mapping, custom DNS |
|
||||||
| [paperless-ngx](paperless-ngx/) | Multi-container | Redis + PostgreSQL + App stack |
|
| [paperless-ngx](paperless-ngx/) | Multi-container | Redis + PostgreSQL + App stack |
|
||||||
@@ -53,7 +54,8 @@ labels:
|
|||||||
- traefik.http.routers.myapp-local.entrypoints=web
|
- traefik.http.routers.myapp-local.entrypoints=web
|
||||||
```
|
```
|
||||||
|
|
||||||
> **Note:** `.local` domains require local DNS (e.g., Pi-hole, Technitium) to resolve to your Traefik host.
|
> **Note:** `.local` domains require local DNS to resolve to your Traefik host.
|
||||||
|
> The [coredns](coredns/) example provides this - edit `Corefile` to set your Traefik IP.
|
||||||
|
|
||||||
### Environment Variables
|
### Environment Variables
|
||||||
|
|
||||||
@@ -88,22 +90,6 @@ stacks:
|
|||||||
autokuma: all # Runs on every configured host
|
autokuma: all # Runs on every configured host
|
||||||
```
|
```
|
||||||
|
|
||||||
### Multi-Container Stacks
|
|
||||||
|
|
||||||
Database-backed apps with multiple services:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
services:
|
|
||||||
redis:
|
|
||||||
image: redis:7
|
|
||||||
db:
|
|
||||||
image: postgres:16
|
|
||||||
app:
|
|
||||||
depends_on:
|
|
||||||
- redis
|
|
||||||
- db
|
|
||||||
```
|
|
||||||
|
|
||||||
### AutoKuma Labels (Optional)
|
### AutoKuma Labels (Optional)
|
||||||
|
|
||||||
The autokuma example demonstrates compose-farm's **multi-host feature** - running the same stack on all hosts using the `all` keyword. AutoKuma itself is not part of compose-farm; it's just a good example because it needs to run on every host to monitor local Docker containers.
|
The autokuma example demonstrates compose-farm's **multi-host feature** - running the same stack on all hosts using the `all` keyword. AutoKuma itself is not part of compose-farm; it's just a good example because it needs to run on every host to monitor local Docker containers.
|
||||||
@@ -124,8 +110,8 @@ cd examples
|
|||||||
# 1. Create the shared network on all hosts
|
# 1. Create the shared network on all hosts
|
||||||
compose-farm init-network
|
compose-farm init-network
|
||||||
|
|
||||||
# 2. Start Traefik first (the reverse proxy)
|
# 2. Start infrastructure (reverse proxy + DNS)
|
||||||
compose-farm up traefik
|
compose-farm up traefik coredns
|
||||||
|
|
||||||
# 3. Start other stacks
|
# 3. Start other stacks
|
||||||
compose-farm up mealie uptime-kuma
|
compose-farm up mealie uptime-kuma
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ deployed:
|
|||||||
- primary
|
- primary
|
||||||
- secondary
|
- secondary
|
||||||
- local
|
- local
|
||||||
|
coredns: primary
|
||||||
mealie: secondary
|
mealie: secondary
|
||||||
paperless-ngx: primary
|
paperless-ngx: primary
|
||||||
traefik: primary
|
traefik: primary
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ hosts:
|
|||||||
stacks:
|
stacks:
|
||||||
# Infrastructure (runs on primary where Traefik is)
|
# Infrastructure (runs on primary where Traefik is)
|
||||||
traefik: primary
|
traefik: primary
|
||||||
|
coredns: primary # DNS for *.local resolution
|
||||||
|
|
||||||
# Multi-host stacks (runs on ALL hosts)
|
# Multi-host stacks (runs on ALL hosts)
|
||||||
# AutoKuma monitors Docker containers on each host
|
# AutoKuma monitors Docker containers on each host
|
||||||
|
|||||||
2
examples/coredns/.env
Normal file
2
examples/coredns/.env
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# CoreDNS doesn't need environment variables
|
||||||
|
# The Traefik IP is configured in the Corefile
|
||||||
22
examples/coredns/Corefile
Normal file
22
examples/coredns/Corefile
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# CoreDNS configuration for .local domain resolution
|
||||||
|
#
|
||||||
|
# Resolves *.local to the Traefik host IP (where your reverse proxy runs).
|
||||||
|
# All other queries are forwarded to upstream DNS.
|
||||||
|
|
||||||
|
# Handle .local domains - resolve everything to Traefik's host
|
||||||
|
local {
|
||||||
|
template IN A {
|
||||||
|
answer "{{ .Name }} 60 IN A 192.168.1.10"
|
||||||
|
}
|
||||||
|
template IN AAAA {
|
||||||
|
# Return empty for AAAA to avoid delays on IPv4-only networks
|
||||||
|
rcode NOERROR
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Forward everything else to upstream DNS
|
||||||
|
. {
|
||||||
|
forward . 1.1.1.1 8.8.8.8
|
||||||
|
cache 300
|
||||||
|
errors
|
||||||
|
}
|
||||||
27
examples/coredns/compose.yaml
Normal file
27
examples/coredns/compose.yaml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# CoreDNS - DNS server for .local domain resolution
|
||||||
|
#
|
||||||
|
# Demonstrates:
|
||||||
|
# - Wildcard DNS for *.local domains
|
||||||
|
# - Config file mounting from stack directory
|
||||||
|
# - UDP/TCP port exposure
|
||||||
|
#
|
||||||
|
# This enables all the .local routes in the examples to work.
|
||||||
|
# Point your devices/router DNS to this server's IP.
|
||||||
|
name: coredns
|
||||||
|
services:
|
||||||
|
coredns:
|
||||||
|
image: coredns/coredns:latest
|
||||||
|
container_name: coredns
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- mynetwork
|
||||||
|
ports:
|
||||||
|
- "53:53/udp"
|
||||||
|
- "53:53/tcp"
|
||||||
|
volumes:
|
||||||
|
- ./Corefile:/root/Corefile:ro
|
||||||
|
command: -conf /root/Corefile
|
||||||
|
|
||||||
|
networks:
|
||||||
|
mynetwork:
|
||||||
|
external: true
|
||||||
Reference in New Issue
Block a user