feat(docker): standalone output for slim frontend image (886MB → 219MB)

This commit is contained in:
null 2026-05-19 21:57:38 -05:00
parent 87802db0f4
commit 6279bd4f31
2 changed files with 7 additions and 10 deletions

View File

@ -32,19 +32,15 @@ ENV NEXT_PUBLIC_API_URL=auto
ENV NEXT_PUBLIC_AUTH_MODE=${NEXT_PUBLIC_AUTH_MODE} ENV NEXT_PUBLIC_AUTH_MODE=${NEXT_PUBLIC_AUTH_MODE}
# Create non-root user before COPY so --chown can reference it. # Create non-root user before COPY so --chown can reference it.
# Using COPY --chown avoids a slow recursive chown on overlay2 (docker/for-linux#388). RUN addgroup -S appgroup && adduser -S -G appgroup appuser
RUN addgroup -S appgroup && adduser -S -G appgroup appuser \
&& chown appuser:appgroup /app
COPY --from=builder --chown=appuser:appgroup /app/.next ./.next # Copy standalone output from builder
# `public/` is optional in Next.js apps; repo may not have it. COPY --from=builder --chown=appuser:appgroup /app/.next/standalone ./
# Avoid failing the build when the directory is absent. COPY --from=builder --chown=appuser:appgroup /app/.next/static ./.next/static
COPY --from=builder --chown=appuser:appgroup /app/package.json ./package.json COPY --from=builder --chown=appuser:appgroup /app/public ./public
COPY --from=builder --chown=appuser:appgroup /app/node_modules ./node_modules
COPY --from=builder --chown=appuser:appgroup /app/next.config.ts ./next.config.ts
USER appuser USER appuser
EXPOSE 3000 EXPOSE 3000
CMD ["npm", "run", "start"] CMD ["node", "server.js"]

View File

@ -1,6 +1,7 @@
import type { NextConfig } from "next"; import type { NextConfig } from "next";
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
output: "standalone",
// In dev, Next may proxy requests based on the request origin/host. // In dev, Next may proxy requests based on the request origin/host.
// Allow common local origins so `next dev --hostname 127.0.0.1` works // Allow common local origins so `next dev --hostname 127.0.0.1` works
// when users access via http://localhost:3000 or http://127.0.0.1:3000. // when users access via http://localhost:3000 or http://127.0.0.1:3000.