Running multiple app instances with Tailscale
I wanted to run multiple copies of the same Rails app on my machine—different branches, same codebase. The usual localhost:3000 wasn’t going to work. Docker Compose binds to host ports, so you can only run one instance at a time unless you start juggling port numbers.
Tailscale turned out to be the answer. Each Docker Compose stack gets its own Tailscale identity, its own hostname. No port conflicts.
How It Works
Tailscale runs as a sidecar container. The web container shares its network namespace, so traffic to the Tailscale IP hits Rails directly:
services:
tailscale:
image: tailscale/tailscale:latest
hostname: ${TS_HOSTNAME}
environment:
- TS_AUTHKEY=${TS_AUTHKEY}
- TS_USERSPACE=true
web:
network_mode: service:tailscale
ports: !override []
environment:
- PORT=80
The ports: !override [] removes the host port bindings entirely. Everything goes through Tailscale.
Fun Hostnames
Each clone generates a random name on first run—adjective plus animal. So I’ve got stayupfront-cosmic-phoenix and stayupfront-lazy-capybara running side by side. Easier to remember than port numbers.
Subdomains
The app uses subdomain routing for multi-tenancy. Since Tailscale only gives you one hostname per node, I’m using sslip.io for subdomains. If your Tailscale IP is 100.123.231.105, then acme.100-123-231-105.sslip.io resolves to that IP. No DNS config needed.
The Commands
./bin/up — Start with Tailscale
./bin/down — Stop
./bin/logs — Follow logs
./bin/ci — Run tests
The up script generates the hostname, waits for Tailscale, prepares the database, and prints the URLs. About 100 lines of bash.
Worth It?
I can now spin up a fresh clone, run ./bin/up, and have a fully isolated instance with its own URL in thirty seconds. No port conflicts, accessible from anywhere on my Tailnet.
If you’re running multiple Docker stacks and tired of port juggling, this seems to work quite nicely. As an added benefit, anybody on your tailnet can now access these urls’ – including your phone! Useful for mobile testing.