diff --git a/Dockerfile b/Dockerfile index 04b6688..6364b91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ -#syntax=docker/dockerfile:1.4 FROM node:18-alpine AS base # Install dependencies only when needed @@ -8,8 +7,13 @@ RUN apk add --no-cache libc6-compat WORKDIR /app # Install dependencies based on the preferred package manager -COPY package.json yarn.lock* ./ -RUN yarn --frozen-lockfile +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm ci; \ + elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \ + else echo "Lockfile not found." && exit 1; \ + fi # Rebuild the source code only when needed @@ -34,24 +38,28 @@ WORKDIR /app ENV NODE_ENV production # Uncomment the following line in case you want to disable telemetry during runtime. -ENV NEXT_TELEMETRY_DISABLED 1 +# ENV NEXT_TELEMETRY_DISABLED 1 -RUN \ - addgroup --system --gid 1001 nodejs; \ - adduser --system --uid 1001 nextjs +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=1001:1001 /app/.next/standalone ./ -COPY --from=builder --chown=1001:1001 /app/.next/static ./.next/static +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static USER nextjs EXPOSE 3000 ENV PORT 3000 -ENV HOSTNAME localhost +# set hostname to localhost +ENV HOSTNAME "0.0.0.0" CMD ["node", "server.js"] \ No newline at end of file