Skip to content

Instantly share code, notes, and snippets.

@calvinf
Last active February 15, 2025 20:37
Show Gist options
  • Save calvinf/2b4342ebebc071b62fa02d3d22159e2a to your computer and use it in GitHub Desktop.
Save calvinf/2b4342ebebc071b62fa02d3d22159e2a to your computer and use it in GitHub Desktop.
Bun + Node.js Dockerfile
# Dockerfile for Bun (package manager) and Node.js (for runtime Next.js)
# this image includes Bun 1.x, Node.js 22, on Alpine, with Git
FROM imbios/bun-node:1-22-alpine-git AS base
RUN apk update && apk upgrade && apk add --no-cache dumb-init
RUN addgroup --system --gid 1002 nodejs
RUN adduser --system --uid 1002 nextjs
# Install dependencies only when needed
FROM base AS builder
WORKDIR /app
COPY . .
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile
# Add `ARG` instructions below if you need `NEXT_PUBLIC_` variables
# then put the value on your fly.toml
# Example:
# ARG NEXT_PUBLIC_SOMETHING
# https://nextjs.org/telemetry
ENV NEXT_TELEMETRY_DISABLED=1
# assumes your package.json build command does the Next.js production build
RUN bun run build
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
# copy the public folder from the project as this is not included in the build process
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
# copy the standalone folder inside the .next folder generated from the build process
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
# copy the static folder inside the .next folder generated from the build process
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 8038
# https://nextjs.org/telemetry
ENV PORT=8038 NODE_ENV=production NEXT_TELEMETRY_DISABLED=1
CMD ["dumb-init","node","server.js"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment