Skip to content

Commit

Permalink
fix: fixing docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
yashd-dev committed Oct 14, 2024
1 parent c28a464 commit 0efb827
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
# Use Node.js 18 Alpine as the base image
FROM node:18-alpine AS base
FROM node:18-alpine

# Install dependencies only when needed
FROM base AS deps
# Add libc6-compat for Alpine compatibility
RUN apk add --no-cache libc6-compat
# Set working directory
WORKDIR /app

# Copy package files to set up dependencies
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 corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi

# Build the application
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
# Copy all files to the working directory
COPY . .
RUN npm run build

ENV NODE_ENV production
# Install dependencies
RUN npm ci

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs
# Build the application
RUN npm run build

EXPOSE 3004
# Expose the port the app runs on
EXPOSE 3000

# Set environment variables
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"
# Start the Next.js application
CMD ["npm", "run", "start"]

# Start the application
CMD ["npm", "start"]

0 comments on commit 0efb827

Please sign in to comment.