Declarative Headscale + Headplane Docker Compose stack with an optional Caddy reverse proxy for automated HTTPS.
Features • Architecture • Quick Start • Connecting Devices • Reverse Proxy
- 100% Declarative & GitOps-Ready: No host-level bash scripts or runtime string manipulations. The entire stack is configured via a single
.envfile. - Modern Web Interface: Bundled with Headplane for visual node management, ACL configuration, and read-only MagicDNS & config view.
- Zero-Config Automatic TLS: Built-in Caddy reverse proxy provisions and renews Let's Encrypt / ZeroSSL certificates automatically.
- Flexible Ingress: Run the built-in Caddy proxy (
COMPOSE_PROFILES=caddy) or seamlessly connect your existing Nginx Proxy Manager, Traefik, or host Nginx. - Container Health & Order: Headscale health checks (
headscale health) ensure Headplane boots strictly when the control plane and database are ready. - Safe Data Persistence: SQLite databases, TLS certificates, and session data live in isolated Docker Named Volumes—no host permission issues (
UID/GID). - Tailscale Compliant: Implements real client IP forwarding (
True-Client-IP), WebSocket streaming, and mobile captive portal detection (/generate_204).
┌────────────────────────────────────────┐
│ Internet / Clients │
└───────────────────┬────────────────────┘
│
443/tcp+udp (HTTPS/H3) │ 3478/udp (STUN)
┌───────────────────────────┴───────────────────────────────┐
▼ │
┌───────────────────┐ │
│ Reverse Proxy │ │
│ (Caddy / NPM) │ │
└─────────┬─────────┘ │
│ │
┌─────────┴──────────────────────┐ │
│ /admin* │ /* │
▼ ▼ ▼
┌──────────────────────┐ ┌────────────────────────────────────────────────┐
│ Headplane │──>│ Headscale │
│ (Web UI) │ │ (Control Plane / Hub / STUN) │
└──────────┬───────────┘ └───────────────────────┬────────────────────────┘
▼ ▼
[headplane-data] [headscale-data]
git clone https://github.com/mikhailde/headscale-stack.git
cd headscale-stackcp .env.example .envEdit .env and configure your settings:
DOMAIN=headscale.example.com
COMPOSE_PROFILES=caddyGenerate a secure 32-character hex secret for Headplane:
openssl rand -hex 16(Copy the output into HEADPLANE_COOKIE_SECRET)
Generate a bcrypt password hash for Caddy Basic Auth:
docker run -it --rm caddy:alpine caddy hash-password(Paste into ADMIN_PASSWORD_HASH in .env. Note: escape each $ as $$, e.g. $$2a$$14$$...)
Warning
Cloudflare DNS Users: If using Cloudflare DNS, set your DNS record proxy status to DNS-only (grey cloud). Cloudflare Proxy blocks Tailscale WebSocket POST requests required by the protocol.
docker compose up -dGenerate a Headscale API key for Headplane:
docker compose exec headscale headscale apikeys create --expiration 90dOpen https://<your-domain>/admin/ in your browser:
- Log in via HTTP Basic Auth using your configured
ADMIN_USERand password. - Enter the generated API key into Headplane to access the dashboard.
- Create your first user under Users (e.g.
default). Clients require an existing user to register. - Configure and save an access policy under Access Control (ACL) before connecting devices. By default,
policy.mode: databasepermits all-to-all traffic until a policy is saved.
Run the following command in your terminal:
tailscale up --login-server https://<your-domain>To authenticate automatically with a pre-auth key:
tailscale up --login-server https://<your-domain> --auth-key <preauth-key>- Open the official Tailscale app.
- Open the menu → Settings → Accounts → Use custom control server.
- Enter your server URL:
https://<your-domain>.
Client Deployment Recipes (Exit Nodes & Server Nodes)
Use this recipe to turn a remote VPS into an exit node for browsing the internet:
services:
tailscale-exit:
image: tailscale/tailscale:stable
container_name: tailscale-exit
restart: unless-stopped
devices:
- /dev/net/tun:/dev/net/tun
cap_add:
- NET_ADMIN
- NET_RAW
sysctls:
- net.ipv4.ip_forward=1
- net.ipv6.conf.all.forwarding=1
ports:
- "41641:41641/udp"
volumes:
- tailscale-state:/var/lib/tailscale
environment:
- TS_AUTHKEY=replace_with_preauth_key
- TS_AUTH_ONCE=true
- TS_HOSTNAME=exit-node
- TS_USERSPACE=false
- TS_STATE_DIR=/var/lib/tailscale
- TS_NO_LOGS_NO_SUPPORT=true
- TS_EXTRA_ARGS=--login-server=https://<your-domain> --advertise-exit-node
volumes:
tailscale-state:Linux performance tip (enables UDP GRO forwarding on the host to prevent exit-node speed throttling):
NETDEV=$(ip -o route get 8.8.8.8 | cut -f 5 -d " ")
sudo ethtool -K "$NETDEV" rx-udp-gro-forwarding on rx-gro-list offUse this recipe to join any Docker host directly into your private tailnet:
services:
tailscale-server:
image: tailscale/tailscale:stable
container_name: tailscale-server
restart: unless-stopped
network_mode: host
devices:
- /dev/net/tun:/dev/net/tun
cap_add:
- NET_ADMIN
- NET_RAW
volumes:
- tailscale-state:/var/lib/tailscale
environment:
- TS_AUTHKEY=replace_with_preauth_key
- TS_AUTH_ONCE=true
- TS_HOSTNAME=server-main
- TS_USERSPACE=false
- TS_STATE_DIR=/var/lib/tailscale
- TS_NO_LOGS_NO_SUPPORT=true
- TS_EXTRA_ARGS=--login-server=https://<your-domain>
volumes:
tailscale-state:Note: With
TS_AUTH_ONCE=true, changes toTS_EXTRA_ARGSare ignored on container restarts after initial registration.
Keep COMPOSE_PROFILES=caddy in .env. Caddy manages Let's Encrypt certificates, HTTP-to-HTTPS redirects, /generate_204 responses, and basic auth out of the box.
- In
.env, setCOMPOSE_PROFILES=(empty string). - Connect your external proxy container to the stack network:
docker network connect headscale-net <your-proxy-container-name>
- Configure your proxy rules:
| Route | Target | Protocol | Notes |
|---|---|---|---|
https://<domain>/admin* |
http://headplane:3000 |
HTTP | Enable WebSockets |
https://<domain>/* |
http://headscale:8080 |
HTTP | Enable WebSockets, pass True-Client-IP |
Notes:
- Nginx Proxy Manager (NPM): Enable Websockets Support and leave Cache Assets and Block Common Exploits disabled.
- Host-installed proxy: Skip step 2, bind
127.0.0.1:8080:8080(headscale) and127.0.0.1:3000:3000(headplane) viacompose.override.yaml, and target127.0.0.1instead of container names.
View Nginx configuration snippet
# Pass real client IP and WebSocket upgrades
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header True-Client-IP $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_buffering off;
proxy_read_timeout 1d;
proxy_send_timeout 1d;
# Captive portal detection (place in port 80 server block before HTTPS redirect)
location = /generate_204 {
return 204;
}
# Headplane Web UI
location = /admin {
return 301 /admin/;
}
location ^~ /admin/ {
proxy_pass http://headplane:3000;
}
# Headscale VPN Control Plane
location / {
proxy_pass http://headscale:8080;
}Headscale allows relaying traffic when direct WireGuard P2P connections cannot be established through strict NATs:
- Embedded DERP Server: Controlled via
DERP_SERVER_ENABLED=true/falsein.env. When enabled, Headscale serves STUN on port3478/udp. If you also use an Exit Node, setderp.server.ipv4/derp.server.ipv6inconfig/headscale.yamlto avoid a DNS deadlock on reconnect. - Global Tailscale DERP Map: Configured in
config/headscale.yamlunderderp.urls.- To run in 100% private / air-gapped mode without sending relay traffic to Tailscale Inc servers, set:
derp: urls: []
- To run in 100% private / air-gapped mode without sending relay traffic to Tailscale Inc servers, set:
config/headscale.yaml and config/headplane.yaml are mounted read-only (:ro). This adheres to GitOps principles: configuration changes are version-controlled in Git rather than modified ad-hoc from a web browser.
If you configure Headplane with an OIDC provider (Google, GitHub, Keycloak), make sure to remove or bypass Caddy Basic Auth. Basic Auth will intercept /admin/oidc/callback and cause OAuth authentication flow failures.
Always back up your data before upgrading. Headscale only supports one minor version upgrade at a time (e.g. 0.28 → 0.29); avoid skipping minor releases when pulling new images on an existing database.
All persistent VPN state (SQLite database and encryption keys) is stored in /var/lib/headscale. (If you enable OIDC in Headplane, also back up /var/lib/headplane.)
Briefly stop the service to flush the SQLite WAL journal into the main database, then copy the data directory directly from the container:
docker compose stop headscale
docker compose cp headscale:/var/lib/headscale ./headscale_backup_$(date +%F_%H-%M)
docker compose start headscaleTo restore from backup directory (restore into a clean volume, or remove any stale db.sqlite-wal / db.sqlite-shm files first):
docker compose stop headscale
docker compose cp ./headscale_backup_<timestamp>/. headscale:/var/lib/headscale/
docker compose start headscaleIf this stack saved you time, please consider giving it a ⭐ Star — it helps more people discover the project!
- juanfont/headscale — Documentation • Example
config.yaml - tale/headplane — Documentation • Example
config.yaml - Caddy — Documentation
- Tailscale — Docker Client Guide
- meerzulee/headscale-setup — Original setup script that inspired this declarative stack.
Note: The Docker Compose stack and configurations are entirely hand-crafted. An LLM was used solely to format and proofread this documentation.
This project is licensed under the MIT License.