Hi,
I’m trying to setup a Tailscale for a NextJS app. This is my setup:
Dockerfile:
# syntax = docker/dockerfile:1
# Adjust NODE_VERSION as desired
ARG NODE_VERSION=lts
FROM node:${NODE_VERSION}-alpine as base
LABEL fly_launch_runtime="Next.js"
# Next.js app lives here
WORKDIR /app
# Set production environment
ENV NODE_ENV="production"
# Throw-away build stage to reduce size of final image
FROM base as build
# Install packages needed to build node modules
RUN apk update && \
apk add build-base gyp pkgconfig python3
# Install node modules
COPY package-lock.json package.json ./
RUN npm ci --include=dev
# Copy application code
COPY . .
# Build application
RUN npm run build
# Remove development dependencies
RUN npm prune --omit=dev
# Final stage for app image
FROM base
# Install sharp for next/Image
RUN npm install sharp
# https://tailscale.com/kb/1132/flydotio/ (simplified)
RUN apk update && apk add ca-certificates iptables ip6tables && rm -rf /var/cache/apk/*
COPY --from=docker.io/tailscale/tailscale:stable /usr/local/bin/tailscaled /app/tailscaled
COPY --from=docker.io/tailscale/tailscale:stable /usr/local/bin/tailscale /app/tailscale
RUN mkdir -p /var/run/tailscale /var/cache/tailscale /var/lib/tailscale
# Copy built application
COPY --from=build /app/.next/standalone /app
COPY --from=build /app/.next/static /app/.next/static
COPY --from=build /app/public /app/public
COPY --from=build /app/start.sh /app/start.sh
# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
# CMD [ "node", "server.js" ]
CMD ["/app/start.sh"]
start.sh:
#!/bin/sh
/app/tailscaled --state=/var/lib/tailscale/tailscaled.state --socket=/var/run/tailscale/tailscaled.sock &
/app/tailscale up --auth-key=${TAILSCALE_AUTHKEY} --hostname=fly-app
node server.js
However, the app crashes with
2024-11-06 18:18:20.907
WARN could not unmount /rootfs: EINVAL: Invalid argument
2024-11-06 18:18:20.900
INFO Starting clean up.
2024-11-06 18:18:20.886
INFO Main child exited normally with code: 1
2024-11-06 18:18:20.130
Node.js v22.11.0
2024-11-06 18:18:20.130
at node:internal/main/run_main_module:36:49
2024-11-06 18:18:20.130
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
2024-11-06 18:18:20.130
at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
2024-11-06 18:18:20.130
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
2024-11-06 18:18:20.130
at Function._load (node:internal/modules/cjs/loader:1128:12)
2024-11-06 18:18:20.130
at Module.load (node:internal/modules/cjs/loader:1318:32)
2024-11-06 18:18:20.130
at Object..js (node:internal/modules/cjs/loader:1689:10)
2024-11-06 18:18:20.130
at Module._compile (node:internal/modules/cjs/loader:1491:20)
2024-11-06 18:18:20.130
at wrapSafe (node:internal/modules/cjs/loader:1469:18)
2024-11-06 18:18:20.130
SyntaxError: Invalid regular expression flags
2024-11-06 18:18:20.130
^
2024-11-06 18:18:20.130
/app/tailscaled --state=/var/lib/tailscale/tailscaled.state --socket=/var/run/tailscale/tailscaled.sock &
2024-11-06 18:18:20.130
/app/start.sh:3
2024-11-06 18:18:20.019
2024/11/06 23:18:20 INFO SSH listening listen_address=[fdaa:0:c47a:a7b:e824:dcb7:e37b:2]:22 dns_server=[fdaa::3]:53
2024-11-06 18:18:19.933
Machine started in 876ms
What am I doing wrong?