Fix Next.js standalone build in Docker

This commit is contained in:
yznahmad 2025-06-20 02:59:38 +03:00
parent a85f4c0cdc
commit afe5528a1b

View File

@ -11,11 +11,7 @@ RUN npm ci
COPY webapp/ . COPY webapp/ .
# Set environment variables for build # Set environment variables for build
# Use a dummy DB_URI during build to prevent connection attempts
ENV DB_URI="mongodb://dummy:password@localhost:27017/dummy"
ENV NODE_ENV=production ENV NODE_ENV=production
# Disable Next.js telemetry during build
ENV NEXT_TELEMETRY_DISABLED=1 ENV NEXT_TELEMETRY_DISABLED=1
# Build the application # Build the application
@ -33,10 +29,13 @@ RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs RUN adduser --system --uid 1001 nextjs
# Copy the built application from the builder stage # Copy the built application from the builder stage
COPY --from=deps /app/next.config.js .
COPY --from=deps /app/public ./public COPY --from=deps /app/public ./public
COPY --from=deps /app/package.json ./package.json
# Automatically leverage output traces to reduce image size # Copy .next/standalone
COPY --from=deps --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=deps --chown=nextjs:nodejs /app/.next/standalone ./
# Copy .next/static
COPY --from=deps --chown=nextjs:nodejs /app/.next/static ./.next/static COPY --from=deps --chown=nextjs:nodejs /app/.next/static ./.next/static
# Set the user to non-root # Set the user to non-root