⭐ Core project · #4

🐳 Tailscale + Docker sidecar

The reusable pattern for putting any container on your tailnet without publishing ports to your LAN. Once you know this, every other Docker-based project (Jellyfin, Vaultwarden, Pi-hole, Home Assistant) follows the same recipe.

⭐ Core Dev Workflow Intermediate ~1 hr Prereqs: M4 (Toolbox)

Why this project

Every Dockerized service ships with `ports: ["8080:80"]` examples that publish the service to your host's LAN. Anyone on your home wifi can hit it; if you accidentally allow incoming on your router, the world can. The sidecar pattern fixes this: each container becomes its own tailnet device, reachable only over your tailnet, with no LAN exposure.

This is genuinely the answer for most "how do I get this Dockerized service onto my tailnet" questions. Same recipe, different service — once you've internalized the pattern, every container project becomes a copy-paste exercise.

Who this helps

What you get

TAILNET DOCKER HOST 📱 / 💻 tailnet client phone or laptop https://ts-nginx.tail-abc.ts.net 🐳 Docker host (your home server) shared network namespace · 127.0.0.1 📡 ts-nginx Tailscale sidecar tag:container 🌐 nginx listening localhost:80 🏠 host LAN ⛔ no port published to LAN

The trick: the Tailscale sidecar and the nginx container share one network namespace via network_mode: service:ts-nginx. From the tailnet, ts-nginx is the device. nginx hears all the traffic on localhost — same thing, from its perspective. The host's LAN is on a separate path that's never published.

Prerequisites

Mental model

Run a Tailscale container as a sidecar to your service container. Both share a network namespace, so the service is reachable on the tailnet via the sidecar's tailnet identity — without ever publishing ports to your host's LAN. From the tailnet's perspective, the sidecar IS the service. From the service's perspective, the sidecar is just localhost.

Steps

Generate an auth key for the sidecar ~3 min

Admin console → Settings → Auth keys → Generate auth key.

  • Reusable: off (single-use; you'll generate fresh per container)
  • Ephemeral: on (so when the container stops, the device cleans itself up)
  • Pre-authorized: on (so you don't have to manually approve)
  • Tags: pick or create tag:container (declare in tagOwners first if needed)

Copy the key. Looks like tskey-auth-XXXXX.

Write a docker-compose.yml ~5 min

Save this as docker-compose.yml on your home server:

services:
  ts-nginx:
    image: tailscale/tailscale:latest
    hostname: ts-nginx
    environment:
      - TS_AUTHKEY=${TS_AUTHKEY?required}
      - TS_EXTRA_ARGS=--advertise-tags=tag:container
      - TS_SERVE_CONFIG=/config/serve.json
      - TS_STATE_DIR=/var/lib/tailscale
      - TS_USERSPACE=false
    volumes:
      - ts-state:/var/lib/tailscale
      - ./serve-config.json:/config/serve.json
      - /dev/net/tun:/dev/net/tun
    cap_add:
      - net_admin
      - sys_module
    restart: unless-stopped

  nginx:
    image: nginx:alpine
    network_mode: service:ts-nginx
    depends_on:
      - ts-nginx
    restart: unless-stopped

volumes:
  ts-state:

The key trick is network_mode: service:ts-nginx on the nginx container — it shares its network namespace with the Tailscale sidecar.

Add a Tailscale Serve config ~2 min

Save this as serve-config.json alongside the compose file:

{
  "TCP": { "443": { "HTTPS": true } },
  "Web": {
    "${TS_CERT_DOMAIN}:443": {
      "Handlers": { "/": { "Proxy": "http://127.0.0.1:80" } }
    }
  }
}

Bring it up ~3 min

export TS_AUTHKEY="tskey-auth-XXXXX"
docker compose up -d

Check docker compose logs ts-nginx — you should see "Success." and the device's tailnet IP.

Visit the service ~1 min

From any tailnet device, navigate to https://ts-nginx.tail-abc.ts.net. Nginx welcome page over HTTPS, valid cert. Check the admin console — ts-nginx appears as a tagged device.

Apply the template to anything else ~5 min per service

Reuse the pattern. The shape is:

services:
  ts-{name}:
    image: tailscale/tailscale:latest
    hostname: ts-{name}
    # ... same Tailscale config ...
  {name}:
    image: {your-service-image}
    network_mode: service:ts-{name}
    # ... your service's config ...

Generate a fresh auth key per service. Adjust the Serve config to point to whatever port your service listens on (Jellyfin = 8096, Grafana = 3000, etc.). Done.

Verify

Common issues

Variations

Where this leads

The next Core project applies this pattern at full scale — engine + proxy + Tailscale sidecar all in one stack, with no host exposure of the underlying service.

→
Next Core project · #5
🤖 Local AI gateway — the private API
Run an LLM on your home rig as a multi-container stack using exactly the sidecar pattern you just learned.
›

Other natural follow-ups (every Featured Self-Hosted project uses this pattern):