A Better Way to Integrate Tailscale on your fly.io-powered App
16 Sept 2022 | servers, docker, fly-io, tailscale
[Update 2024/02/14]: The Tailscale docs seemed to have updated and now follows the changes described in this post.
The official Tailscale docs does explain on how to integrate Tailscale into a fly.io app. However, I’m not a fan of how the Tailscale version and architecture were hardcoded in the Dockerfile
. I prefer my Dockerfile
to always include the latest and greatest Tailscale version, and also I would like to support multi-arch Docker builds.
If you want to achieve the same, just replace the Dockerfile
template like so:
FROM alpine:latest as builder
WORKDIR /app
COPY . ./
# This is where one could build the application code as well.
- FROM alpine:latest as tailscale
- WORKDIR /app
- COPY . ./
- ENV TSFILE=tailscale_1.30.2_amd64.tgz
- RUN wget https://pkgs.tailscale.com/stable/${TSFILE} && tar xzf ${TSFILE} --strip-components=1
- COPY . ./
+ # Obtain tailscale binaries from the official docker image
+ FROM tailscale/tailscale:latest as tailscale
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
FROM alpine:latest
RUN apk update && apk add ca-certificates iptables ip6tables && rm -rf /var/cache/apk/*
# Copy binary to production image
COPY --from=builder /app/start.sh /app/start.sh
- COPY --from=tailscale /app/tailscaled /app/tailscaled
- COPY --from=tailscale /app/tailscale /app/tailscale
+ COPY --from=tailscale /usr/local/bin/tailscaled /app/tailscaled
+ COPY --from=tailscale /usr/local/bin/tailscale /app/tailscale
RUN mkdir -p /var/run/tailscale /var/cache/tailscale /var/lib/tailscale
# Run on container startup.
CMD ["/app/start.sh"]
Dockerfile
from the Tailscale docs with this
Adwin Ying
Self-taught full-stack web dev based in Tokyo.
Occasionally wrecks servers through
self-hosting
and
homelab-ing.