Dockerfile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Copyright (c) Tailscale Inc & AUTHORS
  2. # SPDX-License-Identifier: BSD-3-Clause
  3. # Note that this Dockerfile is currently NOT used to build any of the published
  4. # Tailscale container images and may have drifted from the image build mechanism
  5. # we use.
  6. # Tailscale images are currently built using https://github.com/tailscale/mkctr,
  7. # and the build script can be found in ./build_docker.sh.
  8. #
  9. # If you want to build local images for testing, you can use make.
  10. #
  11. # To build a Tailscale image and push to the local docker registry:
  12. #
  13. # $ REPO=local/tailscale TAGS=v0.0.1 PLATFORM=local make publishdevimage
  14. #
  15. # To build a Tailscale image and push to a remote docker registry:
  16. #
  17. # $ REPO=<your-registry>/<your-repo>/tailscale TAGS=v0.0.1 make publishdevimage
  18. #
  19. # This Dockerfile includes all the tailscale binaries.
  20. #
  21. # To build the Dockerfile:
  22. #
  23. # $ docker build -t tailscale/tailscale .
  24. #
  25. # To run the tailscaled agent:
  26. #
  27. # $ docker run -d --name=tailscaled -v /var/lib:/var/lib -v /dev/net/tun:/dev/net/tun --network=host --privileged tailscale/tailscale tailscaled
  28. #
  29. # To then log in:
  30. #
  31. # $ docker exec tailscaled tailscale up
  32. #
  33. # To see status:
  34. #
  35. # $ docker exec tailscaled tailscale status
  36. FROM golang:1.25-alpine AS build-env
  37. WORKDIR /go/src/tailscale
  38. COPY go.mod go.sum ./
  39. RUN go mod download
  40. # Pre-build some stuff before the following COPY line invalidates the Docker cache.
  41. RUN go install \
  42. github.com/aws/aws-sdk-go-v2/aws \
  43. github.com/aws/aws-sdk-go-v2/config \
  44. gvisor.dev/gvisor/pkg/tcpip/adapters/gonet \
  45. gvisor.dev/gvisor/pkg/tcpip/stack \
  46. golang.org/x/crypto/ssh \
  47. golang.org/x/crypto/acme \
  48. github.com/coder/websocket \
  49. github.com/mdlayher/netlink
  50. COPY . .
  51. # see build_docker.sh
  52. ARG VERSION_LONG=""
  53. ENV VERSION_LONG=$VERSION_LONG
  54. ARG VERSION_SHORT=""
  55. ENV VERSION_SHORT=$VERSION_SHORT
  56. ARG VERSION_GIT_HASH=""
  57. ENV VERSION_GIT_HASH=$VERSION_GIT_HASH
  58. ARG TARGETARCH
  59. RUN GOARCH=$TARGETARCH go install -ldflags="\
  60. -X tailscale.com/version.longStamp=$VERSION_LONG \
  61. -X tailscale.com/version.shortStamp=$VERSION_SHORT \
  62. -X tailscale.com/version.gitCommitStamp=$VERSION_GIT_HASH" \
  63. -v ./cmd/tailscale ./cmd/tailscaled ./cmd/containerboot
  64. FROM alpine:3.22
  65. RUN apk add --no-cache ca-certificates iptables iproute2 ip6tables
  66. # Alpine 3.19 replaced legacy iptables with nftables based implementation.
  67. # Tailscale is used on some hosts that don't support nftables, such as Synology
  68. # NAS, so link iptables back to legacy version. Hosts that don't require legacy
  69. # iptables should be able to use Tailscale in nftables mode. See
  70. # https://github.com/tailscale/tailscale/issues/17854
  71. RUN rm /usr/sbin/iptables && ln -s /usr/sbin/iptables-legacy /usr/sbin/iptables
  72. RUN rm /usr/sbin/ip6tables && ln -s /usr/sbin/ip6tables-legacy /usr/sbin/ip6tables
  73. COPY --from=build-env /go/bin/* /usr/local/bin/
  74. # For compat with the previous run.sh, although ideally you should be
  75. # using build_docker.sh which sets an entrypoint for the image.
  76. RUN mkdir /tailscale && ln -s /usr/local/bin/containerboot /tailscale/run.sh