Fix Docker build with Next.js standalone output

- Enable outputStandalone in next.config.js for better Docker compatibility
- Update Dockerfile to properly copy standalone output files
- Change CMD to use node server.js for standalone builds
- This should resolve the @/lib module resolution issues in Docker builds
This commit is contained in:
2025-09-15 20:10:29 +02:00
parent 3c7fc63ca8
commit 407e14faa6
2 changed files with 15 additions and 7 deletions

View File

@@ -48,10 +48,10 @@ RUN adduser --system --uid 1001 nextjs
# Copy node_modules from deps stage
COPY --from=deps /app/node_modules ./node_modules
# Copy built application
# Copy built application (standalone output)
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
# Set the correct permission for prerender cache
RUN chown -R nextjs:nodejs .next
@@ -64,5 +64,5 @@ EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"
# Start the application
CMD ["npm", "start"]
# Start the application (standalone)
CMD ["node", "server.js"]

View File

@@ -10,12 +10,20 @@ const nextConfig = {
ignoreBuildErrors: true,
},
experimental: {
// Enable standalone output for better Docker compatibility
outputStandalone: true,
},
webpack: (config) => {
webpack: (config, { isServer, dev }) => {
config.resolve.alias = {
...config.resolve.alias,
'@': require('path').resolve(__dirname, 'src'),
'@': require('path').join(__dirname, 'src'),
};
// Optional: Add debug logging
if (dev) {
console.log('Webpack alias config:', config.resolve.alias);
}
return config;
},
env: {