Tailscale
Put each container on your Tailscale network. You can then reach servers running in a container from your other devices, and the container can reach services on your tailnet.
Create an auth key
In the Tailscale admin console, generate an auth key that is:
- Reusable, so every container can use it.
- Ephemeral, so Tailscale removes a container’s device 30 to 60 minutes after it goes offline, for example after
isodev down. - Pre-approved and tagged, for example with
tag:isodev, so you can control what the containers reach with access rules.
Save it as ~/.config/isodev/tailscale-auth-key, readable only by you (chmod 600).
Set up
Use the files in examples/guides/tailscale:
# yaml-language-server: $schema=https://isodev.dyszkiewicz.me/config.schema.json
# Each container on your tailnet, logged in with tailscale-auth-key.
image: isodev-tailscale:latest
build:
context: image
# Tailscale needs to create a network device in the container.
privileged: true
volumes:
- type: bind
source: tailscale-auth-key
target: /run/secrets/tailscale-auth-key
read_only: true
# Tailscale's state, private to each container, so its device and address
# survive isodev stop and up --recreate. isodev down removes it.
- type: volume
target: /var/lib/tailscale
lifecycle:
on_start:
scripts:
- file: hooks/tailscale.shFROM ubuntu:24.04
ARG DEBIAN_FRONTEND=noninteractive
# mise installs tools to ~/.local/share/mise and puts them on PATH through its
# shims. /usr/local/bin comes first, so files mounted there win.
ENV PATH=/root/.local/bin:/usr/local/sbin:/usr/local/bin:/root/.local/share/mise/shims:/usr/sbin:/usr/bin:/sbin:/bin
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates curl git \
&& rm -rf /var/lib/apt/lists/*
# mise, which installs the tools.
RUN curl -fsSL https://mise.run | MISE_INSTALL_PATH=/usr/local/bin/mise sh
# Tailscale, and jq for the hook.
RUN mise use --global tailscale jq#!/bin/sh
# Runs whenever Isodev creates or starts the container.
set -eu
# Start the Tailscale daemon if it isn't running, then log in once.
mkdir -p /var/log/isodev /var/lib/tailscale
if ! tailscale status --json >/dev/null 2>&1; then
tailscaled --state=/var/lib/tailscale/tailscaled.state </dev/null >/var/log/isodev/tailscaled.log 2>&1 &
fi
attempt=0
until tailscale status --json >/dev/null 2>&1; do
attempt=$((attempt + 1))
if [ "$attempt" -ge 30 ]; then
echo "tailscaled did not start; recent log:" >&2
tail -n 20 /var/log/isodev/tailscaled.log >&2
exit 1
fi
sleep 1
done
if [ "$(tailscale status --json | jq -r .BackendState)" != Running ]; then
tailscale up --auth-key=file:/run/secrets/tailscale-auth-key --timeout=60s
fiThe hook runs whenever Isodev starts the container, so Tailscale comes back after isodev stop and isodev up. Tailscale’s state is in a private volume, so the container keeps its device, name and address across isodev stop, isodev up and isodev up --recreate, instead of joining as a new device each time. isodev down removes the volume, and the ephemeral key lets Tailscale remove the device.
If a container stays stopped for longer than about 30 minutes, Tailscale removes its ephemeral device. The hook then logs in again with the auth key when the container starts, and the container may get a new address.
To also use subnet routes advertised on your tailnet, add --accept-routes to tailscale up.
Use it
isodev up --recreate
isodev exec tailscale statusEach container joins as a device named after its container, isodev-<hash>; isodev ls shows which workspace it belongs to. Servers in the container are reachable at the address from isodev exec tailscale ip -4, or at the device name with MagicDNS.
Trade-offs
- Containers are privileged. See Security.
- Containers are on your tailnet. Use the key’s tag in your access rules to limit what they can reach, and who can reach them.
- Without an ephemeral key, removed containers stay on the tailnet as offline devices until you remove them in the admin console.