Open AdisonCavani opened 1 month ago
@AdisonCavani What errors are you seeing in the console?
@samcx the website is blank and console shows errors:
I'm using Nextjs (standalone output) with Dockerfile and docker-compose.yml
In my local, it builds and runs correctly, but when i deploy in AWS EC2, it fails in run stage.
Here are the files:
FROM node:18-alpine AS base
# 1. Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
# 2. Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
RUN npx prisma generate
RUN npm run build
# 3. Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
ENV NEXT_TELEMETRY_DISABLED=1
ENV HOSTNAME="0.0.0.0"
# Note: Don't expose ports here, Compose will handle that for us
USER nextjs
CMD ["node", "server.js"]
services:
app:
build:
context: ../app_enterbase
container_name: app
ports:
- "3000:3000"
volumes:
# - ../app_enterbase:/app
- .:/app
- /app/node_modules
- /app/.next
Error in AWS EC2 with docker when its in run stage:
✔ Container app Created 0.6s Attaching to app app | node:internal/modules/cjs/loader:1143 app | throw err; app | ^ app | app | Error: Cannot find module '/app/server.js' app | at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15) app | at Module._load (node:internal/modules/cjs/loader:981:27) app | at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) app | at node:internal/main/run_main_module:28:49 { app | code: 'MODULE_NOT_FOUND', app | requireStack: [] app | } app | app | Node.js v18.20.4
Please help!
Wow, I thought I was the edge case. Saw this as well today. I've got the front page rendering now, not sure what I did but front page will not reflect any changes to it, although I can add and build secondary pages which render correctly.
Link to the code that reproduces this issue
https://github.com/AdisonCavani/nextjs-docker-reproduction
To Reproduce
Current vs. Expected behavior
Current: Website is not loading. React throws errors into console.
Expected: Website should work
Provide environment information
Which area(s) are affected? (Select all that apply)
Output (export/standalone)
Which stage(s) are affected? (Select all that apply)
next start (local), Other (Deployed)
Additional context
When you change the /app folder name to something else, the website is working fine.