Next.js Discord

Discord Forum

Turbopack almost 2x slower in `docker build` compared to webpack.

Unanswered
Pink salmon posted this in #help-forum
Open in Discord
Pink salmonOP
I'm using Next.js 16.

Slow specifically in creating an optimized production build process.

The build times are as follows:
- Turbopack in Docker build: 119.0s
=> [builder 4/4] RUN bun run build
=> => # $ NODE_OPTIONS='--max-old-space-size=8192' next build
=> => #    ▲ Next.js 16.0.0 (turbopack)
=> => #    - Environments: .env
=> => #    Creating an optimized production build ...
=> => #  ✓ Compiled successfully in 119s


- Webpack in Docker build: 70s
=> [builder 4/4] RUN bun run build --webpack                                             
=> => # $ NODE_OPTIONS='--max-old-space-size=8192' next build --webpack
=> => #    ▲ Next.js 16.0.0 (webpack)
=> => #    - Environments: .env
=> => #    Creating an optimized production build ...
=> => #  ✓ Compiled successfully in 70s



These times reflect only the build process in Docker and do not include other Docker build processes.

When running the build outside of Docker, the results are as follows:

- Turbopack: 38s
- Webpack: 88s

I'm using Orbstack with no limits on CPU and RAM, and these tests are conducted on an M4 Pro with a 14-core CPU.


FROM node:22-alpine AS base

# System dependencies
FROM base AS base-runtime
RUN apk add --no-cache libc6-compat curl bash && \
  curl -fsSL https://bun.sh/install | bash
ENV PATH="/root/.bun/bin:${PATH}"

# Stage 1: Install application dependencies
FROM base-runtime AS deps
WORKDIR /app
COPY package.json bun.lockb* ./
RUN bun install --frozen-lockfile

# Stage 2: Build application
FROM base-runtime AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN bun run build --webpack

# Stage 3: Production runtime
FROM base-runtime AS runner
WORKDIR /app

RUN addgroup --system --gid 1001 nodejs && \
  adduser --system --uid 1001 nextjs && \
  mkdir -p .next \
  public && \
  chown nextjs:nodejs .next

COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

RUN chown -R nextjs:nodejs /app

USER nextjs

EXPOSE 3000

ENV PORT=3000 \
  HOSTNAME="0.0.0.0"

CMD ["node", "server.js"]

0 Replies