From 3f6c4192fc7cbd9e2785cfce236775a23168922a Mon Sep 17 00:00:00 2001 From: Nishant Date: Sat, 2 Mar 2024 22:11:55 +0530 Subject: [PATCH] nextjs docker compose running --- apps/next-client/Dockerfile | 47 ++++++------------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/apps/next-client/Dockerfile b/apps/next-client/Dockerfile index 9e6bbb0..2ab3450 100644 --- a/apps/next-client/Dockerfile +++ b/apps/next-client/Dockerfile @@ -1,27 +1,22 @@ FROM node:20-alpine3.18 AS base -# Install dependencies only when needed -FROM base AS deps # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine # to understand why libc6-compat might be needed. RUN apk add --no-cache libc6-compat + # Set working directory in the container WORKDIR /app + # first create these directories, else the copying won't work. RUN mkdir -p apps/next-client -# Copy package.json and package-lock.json to the container -COPY --chown=node:node package.json ./ + +COPY --chown=node:node package.json . +COPY --chown=node:node yarn.lock . COPY --chown=node:node ./apps/next-client/package.json ./apps/next-client + # Install dependencies RUN yarn --frozen-lockfile - -# Rebuild the source code only when needed -FROM base AS builder -WORKDIR /app - -COPY --from=deps /app/package.json /app -COPY --from=deps /app/node_modules ./node_modules # Copy the rest of the application code to the container COPY ./apps/next-client ./apps/next-client @@ -33,35 +28,7 @@ COPY ./apps/next-client ./apps/next-client # Build the Next.js app RUN yarn workspace next-client build -# Production image, copy all the files and run next -FROM base AS runner -WORKDIR /app -ENV NODE_ENV production -# Uncomment the following line in case you want to disable telemetry during runtime. -# ENV NEXT_TELEMETRY_DISABLED 1 -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs - -COPY --from=builder /app/apps/next-client/public ./apps/next-client/public - -# Set the correct permission for prerender cache -RUN mkdir apps/next-client/.next -RUN chown nextjs:nodejs apps/next-client/.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/apps/next-client/.next/standalone ./ -COPY --from=builder --chown=nextjs:nodejs /app/apps/next-client/.next/static ./apps/next-client/.next/static - -USER nextjs - # Expose the port Next.js app runs on (default is 3000) EXPOSE 3000 -# set hostname to localhost -ENV HOSTNAME "0.0.0.0" - -# server.js is created by next build from the standalone output -# https://nextjs.org/docs/pages/api-reference/next-config-js/output -# CMD ["node", "./apps/next-client/server.js"] -CMD [ "ls" ] \ No newline at end of file +CMD [ "yarn", "workspace", "next-client", "start:prod" ] \ No newline at end of file