TailscaleGuide
Illustrated title card for the guide: Tailscale in Docker: Auth Keys, Saved State and Serve
Setup Guides

Tailscale in Docker: Auth Keys, Saved State and Serve

Run the official Tailscale Docker image, keep its device identity across restarts, and use Docker Compose and Tailscale Serve for private HTTPS.

By TailscaleGuide Editorial · ·Updated · 4 min read

Run the official tailscale/tailscale:latest image with an auth key in TS_AUTHKEY and a persistent mount at /var/lib/tailscale. Standalone Docker guide Set TS_STATE_DIR to that same path to keep the container’s device identity across restarts. Docker parameters For a web app, the ScaleTail Compose example shares the Tailscale container’s network with the app and gives it a private HTTPS address through Tailscale Serve. ScaleTail standard setup

Create an auth key

You’ll need a tailnet and an account with permission to generate auth keys. Standalone Docker guide If you’re starting from scratch, follow the Tailscale setup guide.

  1. In the Tailscale admin console, open Keys. Under Auth keys, select Generate auth key and enter a description. Standalone Docker guide
  2. For the single-device Compose example, leave Ephemeral off. Turn on Pre-approved if your tailnet uses device approval. ScaleTail quickstart
  3. Select Generate key and copy the key before closing the dialog. Standalone Docker guide
CredentialWhen to use it
One-off auth keyUse it to enroll a single device once. Auth keys
Reusable auth keyUse it when one key needs to enroll multiple devices. Keep it in a key vault. Auth keys
OAuth clientUse it when automation needs to generate auth keys as needed. Grant the client the auth_keys scope and select the tags it can use. OAuth clients

To register a tagged node with TS_AUTHKEY=YOUR_OAUTH_CLIENT_SECRET, pass a matching tag in TS_EXTRA_ARGS, for example TS_EXTRA_ARGS=--advertise-tags=tag:ci. Docker parameters OAuth clients With this form, the node is ephemeral by default. Append ?ephemeral=false to the secret to register a non-ephemeral node. Docker parameters

The image also accepts TS_CLIENT_ID=YOUR_CLIENT_ID and TS_CLIENT_SECRET=YOUR_CLIENT_SECRET together for OAuth authentication and auth key generation. Omit TS_AUTHKEY when using that pair. Docker parameters

Run a standalone Tailscale container

Replace YOUR_AUTH_KEY with the key you generated. The example starts the Tailscale client by itself and enrolls it as tailscale-nginx. Standalone Docker guide

docker run -d \
  --name tailscale \
  --hostname tailscale-nginx \
  -e TS_AUTHKEY='YOUR_AUTH_KEY' \
  -e TS_STATE_DIR=/var/lib/tailscale \
  -v ./tailscale-state:/var/lib/tailscale \
  --cap-add=net_admin \
  --cap-add=net_raw \
  --restart unless-stopped \
  tailscale/tailscale:latest

Open Machines in the Tailscale admin console and look for tailscale-nginx to confirm it joined your tailnet. Standalone Docker guide

Keep the device identity when you recreate the container

The standalone example mounts ./tailscale-state at /var/lib/tailscale. The Homepage Compose example mounts ./ts/state at that same container path. Both set TS_STATE_DIR=/var/lib/tailscale. Standalone Docker guide Homepage Compose file

Keep ./ts/state when recreating the Homepage stack. If that directory is lost, the container needs a valid auth key and joins as a new device. ScaleTail standard setup

The Homepage example sets TS_AUTH_ONCE=true. Homepage Compose file For the standalone container, set it if you’re persisting state and want it to log in only when unauthenticated. The image defaults to false, which forces login on every start. Docker parameters

Choose userspace or kernel networking

ModeWhen to use it and what it needs
UserspaceThis is the image default. Docker parameters Use it when the host cannot supply /dev/net/tun. Other processes in the container can connect through a SOCKS5 or HTTP proxy. Userspace networking
KernelThe Homepage example sets TS_USERSPACE=false, passes through /dev/net/tun under devices, and adds net_admin under cap_add. Homepage Compose file

Start Homepage with the Tailscale sidecar

The ScaleTail quickstart calls for a Linux host with Docker Engine, Git, and Docker Compose 2.23.1 or later. Check your version with docker compose version. ScaleTail quickstart

On the admin console’s DNS page, enable MagicDNS and HTTPS Certificates. Enabling HTTPS puts device names in public certificate transparency logs. ScaleTail quickstart

Clone ScaleTail and enter the Homepage service directory. ScaleTail quickstart Homepage setup

git clone https://github.com/tailscale-dev/ScaleTail.git
cd ScaleTail/services/homepage

Edit the included .env, keeping the service name homepage. Use a fresh one-off key if you already used the first key for the standalone container. Homepage setup ScaleTail quickstart Auth keys

Set the two values below. In TAILNET_NAME, enter the tailnet name without .ts.net. The Compose file uses it to build HOMEPAGE_ALLOWED_HOSTS for homepage.<tailnet>.ts.net. ScaleTail quickstart Homepage setup

TS_AUTHKEY=YOUR_AUTH_KEY
TAILNET_NAME=YOUR_TAILNET_NAME

ScaleTail tracks that file in Git. ScaleTail quickstart

Before starting, remove the /var/run/docker.sock:/var/run/docker.sock:ro mount from the application’s volumes if you won’t use Homepage’s Docker integration. Treat access to the socket as root access to the Docker host, even with :ro. Homepage setup Homepage Compose file

The published Compose file puts network_mode: service:tailscale on the application service. This makes Homepage share the Tailscale sidecar’s network namespace. ScaleTail standard setup

services:
  application:
    network_mode: service:tailscale

Start the stack and check that the tailscale service reports healthy. Homepage starts after that check passes. If a container fails to start, run docker compose logs. ScaleTail quickstart

docker compose up -d
docker compose ps

Open the private HTTPS page and check Serve

The Compose file provides /config/serve.json and points TS_SERVE_CONFIG at it. The configuration sends HTTPS requests to Homepage at http://127.0.0.1:3000 and disables Funnel for that endpoint. Homepage Compose file

From a device on your tailnet, open https://homepage.<tailnet>.ts.net, replacing <tailnet> with your tailnet name. Homepage setup The first request can take up to a minute while Tailscale requests the certificate. ScaleTail quickstart Homepage has no login of its own, and your tailnet’s access rules apply to the Serve endpoint. Homepage setup Tailscale Serve

To change the Homepage example’s Serve configuration, edit the configs block in compose.yaml and apply it with docker compose up -d --force-recreate. ScaleTail standard setup If you use a bind mount for your own Serve configuration, mount the directory containing the JSON file so Tailscale detects file updates. Docker parameters

For access to other devices on a local subnet, see the Tailscale subnet router guide.

Evidence and limits. Tailscale’s Docker and Serve documentation and the ScaleTail Homepage example were checked on November 28, 2026. The example uses the tailscale/tailscale:latest image tag. Homepage Compose file No hands-on testing was performed for this guide.

Sources

  1. Connect a Docker container to your tailnet with standalone Docker
  2. Docker configuration parameters
  3. Auth keys
  4. OAuth clients
  5. Userspace networking mode (for containers)
  6. ScaleTail quickstart
  7. ScaleTail Homepage setup
  8. ScaleTail Homepage Compose file
  9. ScaleTail standard setup
  10. Tailscale Serve

Related