diff --git a/Dockerfile b/Dockerfile index 7926ee4..733930f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,24 +18,23 @@ RUN npm run build FROM node:20-alpine AS runner WORKDIR /app -ENV NODE_ENV production +ENV NODE_ENV=production +ENV HOSTNAME="0.0.0.0" +ENV PORT=3000 # Create a non-root user -RUN addgroup -g 1001 -S nodejs -RUN adduser -S nextjs -u 1001 +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nextjs -u 1001 -# Copy built application -COPY --from=builder /app/public ./public -COPY --from=builder /app/.next/standalone ./ -COPY --from=builder /app/.next/static ./.next/static - -# Change ownership -RUN chown -R nextjs:nodejs /app +# Copy standalone build output with proper ownership +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static +COPY --from=builder --chown=nextjs:nodejs /app/public ./public USER nextjs EXPOSE 3000 -ENV PORT 3000 - -CMD ["node", "server.js"] \ No newline at end of file +# Use ENTRYPOINT and CMD for better container control +ENTRYPOINT ["node"] +CMD ["server.js"] \ No newline at end of file