refactor: update Dockerfile and docker-compose.yml for Next.js 15 optimization and standalone output

This commit is contained in:
hamed
2025-12-10 14:44:41 +03:30
parent 6f0c29d700
commit 8e5e8e1e9d
3 changed files with 9 additions and 8 deletions
+2 -2
View File
@@ -80,12 +80,12 @@ services:
# - /tmp # - /tmp
# - /app/.next/cache # - /app/.next/cache
# Networks (Coolify uses bridge network) # Networks
networks: networks:
- coolify - coolify
# Network configuration # Network configuration
networks: networks:
coolify: coolify:
driver: bridge name: coolify
external: true external: true
+5 -6
View File
@@ -65,12 +65,11 @@ ENV HOSTNAME="0.0.0.0"
RUN addgroup --system --gid 1001 nodejs && \ RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs adduser --system --uid 1001 nextjs
# Copy necessary files from builder # Copy necessary files from builder (standalone mode)
COPY --from=builder --chown=nextjs:nodejs /app/next.config.js ./ COPY --from=builder --chown=nextjs:nodejs /app/next.config.js ./
COPY --from=builder --chown=nextjs:nodejs /app/public ./public COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
# Switch to non-root user # Switch to non-root user
USER nextjs USER nextjs
@@ -85,5 +84,5 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
# Use dumb-init to handle signals properly # Use dumb-init to handle signals properly
ENTRYPOINT ["dumb-init", "--"] ENTRYPOINT ["dumb-init", "--"]
# Start Next.js in production mode # Start Next.js in standalone mode
CMD ["node_modules/.bin/next", "start"] CMD ["node", "server.js"]
+2
View File
@@ -23,6 +23,8 @@ const nextConfig = {
trailingSlash: false, trailingSlash: false,
compress: true, compress: true,
poweredByHeader: false, poweredByHeader: false,
// Enable standalone output for Docker
output: 'standalone',
}; };
module.exports = nextConfig; module.exports = nextConfig;