feat: optimize Docker build with Next.js standalone output configuration
This commit is contained in:
parent
16825648ed
commit
11188330fe
19
Dockerfile
19
Dockerfile
@ -18,7 +18,7 @@ ENV NODE_ENV=production
|
|||||||
COPY myfavstuff/package.json myfavstuff/package-lock.json* ./
|
COPY myfavstuff/package.json myfavstuff/package-lock.json* ./
|
||||||
|
|
||||||
# Install dependencies including dev dependencies needed for build
|
# Install dependencies including dev dependencies needed for build
|
||||||
# npm ci should install eslint from devDependencies
|
# This will also install eslint if it's in devDependencies and package-lock.json is up to date
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
|
|
||||||
# Copy the rest of your app's source code from the 'myfavstuff' subdirectory
|
# Copy the rest of your app's source code from the 'myfavstuff' subdirectory
|
||||||
@ -34,21 +34,22 @@ RUN echo "--- Debugging Build Environment Variables (Passed to Build) ---" && \
|
|||||||
NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY \
|
NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY \
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
# Production stage
|
# Production stage (runner)
|
||||||
FROM node:20-alpine AS runner
|
FROM node:20-alpine AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
# Runtime environment variables will be set by Coolify directly in the container environment.
|
# Runtime environment variables will be set by Coolify directly in the container environment.
|
||||||
# We don't need to re-declare ARGs here or pass them from the builder stage for runtime ENV.
|
|
||||||
# Coolify injects them into the final container.
|
|
||||||
|
|
||||||
# Create a non-root user for security IN THIS STAGE
|
# Create a non-root user for security IN THIS STAGE
|
||||||
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
|
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
|
||||||
|
|
||||||
COPY --from=builder /app/public ./public
|
# Copy standalone output from the builder stage
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
# If you decide to use standalone output later, you'd copy /app/.next/standalone and /app/.next/static
|
# Copy static assets
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
# Copy public assets (if any, like favicon, images in /public)
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
||||||
|
|
||||||
USER nextjs
|
USER nextjs
|
||||||
|
|
||||||
@ -57,5 +58,5 @@ EXPOSE 3000
|
|||||||
ENV PORT=3000
|
ENV PORT=3000
|
||||||
ENV HOSTNAME=0.0.0.0
|
ENV HOSTNAME=0.0.0.0
|
||||||
|
|
||||||
# The start script in package.json should be `next start`
|
# Run the Next.js standalone server
|
||||||
CMD ["npm", "start"]
|
CMD ["node", "server.js"]
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
// output: 'standalone', // Consider this if you want a smaller Docker image, requires Next.js 12.2+
|
output: 'standalone', // Enable standalone output for optimized Docker builds
|
||||||
|
|
||||||
// Configure images if using them from external domains
|
// Configure images if using them from external domains
|
||||||
images: {
|
images: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user