Requires Next.js to be configured to output a standalone bundle. See more here.
- Required system packages are cached during the build stage.
- Next.js builds are cached during the build stage.
- Next.js telemetry is disabled by default.
# syntax = docker/dockerfile:1 | |
# Adjust BUN_VERSION as desired | |
ARG BUN_VERSION=1.1.1 | |
FROM oven/bun:${BUN_VERSION}-slim as base | |
LABEL fly_launch_runtime="Next.js" | |
# Next.js app lives here | |
WORKDIR /app | |
# Set production environment | |
ENV NEXT_TELEMETRY_DISABLED="1" \ | |
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 --mount=type=cache,id=cache,target=/var/cache/apt \ | |
--mount=type=cache,id=lib,target=/var/lib/apt \ | |
apt-get update -qq && \ | |
apt-get install --no-install-recommends -y build-essential ca-certificates curl pkg-config python-is-python3 | |
# Install node modules | |
COPY --link bun.lockb package.json ./ | |
RUN --mount=type=cache,id=bun,target=/root/.bun \ | |
bun install --frozen-lockfile | |
# Copy application code | |
COPY --link . . | |
# Include Next.js cache | |
RUN mkdir -p /app/.next/cache | |
# Build application | |
RUN --mount=type=cache,id=nextjs,target=/app/.next/cache \ | |
bun run build | |
# Final stage for app image | |
FROM base AS run | |
# Copy built application | |
COPY --from=build /app/.next/standalone ./ | |
COPY --from=build /app/.next/static ./.next/static | |
# Start the server by default, this can be overwritten at runtime | |
EXPOSE 3000 | |
CMD ["bun", "run", "server.js"] |
@deadcoder0904 It's used for building dependencies that depend on node-gyp. It may be removed if you do not have such dependencies.
I'm not certain if this Dockerfile works with sharp
as I generally manually implement image optimization in my Next.js projects.
is this fly specific? why do you need it?
also, does next/image through error about sharp? i faced lots of issues while getting sharp to work next/image but finally found a working solution using pnpm by installing it separately.