Skip to content

Commit

Permalink
nextjs docker compose running
Browse files Browse the repository at this point in the history
  • Loading branch information
nishkohli96 committed Mar 2, 2024
1 parent 27fae0b commit 3f6c419
Showing 1 changed file with 7 additions and 40 deletions.
47 changes: 7 additions & 40 deletions apps/next-client/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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" ]
CMD [ "yarn", "workspace", "next-client", "start:prod" ]

0 comments on commit 3f6c419

Please sign in to comment.