fix: Docker container deployment issues
All checks were successful
build-website / build (push) Successful in 2m14s
All checks were successful
build-website / build (push) Successful in 2m14s
- Set proper environment variables (NODE_ENV, HOSTNAME, PORT) - Use ENTRYPOINT and CMD for better container control - Fix ownership issues with --chown on COPY commands - Ensure public directory is copied correctly - Combine user creation commands for efficiency The container should now start properly with the Next.js standalone server. 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
25
Dockerfile
25
Dockerfile
@@ -18,24 +18,23 @@ RUN npm run build
|
|||||||
FROM node:20-alpine AS runner
|
FROM node:20-alpine AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
ENV NODE_ENV production
|
ENV NODE_ENV=production
|
||||||
|
ENV HOSTNAME="0.0.0.0"
|
||||||
|
ENV PORT=3000
|
||||||
|
|
||||||
# Create a non-root user
|
# Create a non-root user
|
||||||
RUN addgroup -g 1001 -S nodejs
|
RUN addgroup -g 1001 -S nodejs && \
|
||||||
RUN adduser -S nextjs -u 1001
|
adduser -S nextjs -u 1001
|
||||||
|
|
||||||
# Copy built application
|
# Copy standalone build output with proper ownership
|
||||||
COPY --from=builder /app/public ./public
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
COPY --from=builder /app/.next/standalone ./
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
COPY --from=builder /app/.next/static ./.next/static
|
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
||||||
|
|
||||||
# Change ownership
|
|
||||||
RUN chown -R nextjs:nodejs /app
|
|
||||||
|
|
||||||
USER nextjs
|
USER nextjs
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
ENV PORT 3000
|
# Use ENTRYPOINT and CMD for better container control
|
||||||
|
ENTRYPOINT ["node"]
|
||||||
CMD ["node", "server.js"]
|
CMD ["server.js"]
|
||||||
Reference in New Issue
Block a user