Skip to content

Commit

Permalink
update docker file and ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
gregrickaby committed May 9, 2024
1 parent 1098d82 commit 3e4c6b7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.next
.git
36 changes: 30 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,46 @@
# https://hub.docker.com/_/node
FROM node:20-alpine

# 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

# Create and change to the app directory.
WORKDIR /usr/src/app
WORKDIR /app

# Install dependencies based on the preferred package manager.
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

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./
# Install PM2.
RUN npm install -g pm2

# Install production dependencies.
RUN npm ci

# Set the user to non-root and create necessary directories.
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# Change the ownership of the app directory to the nodejs user.
RUN chown nextjs:nodejs /app

# Copy local code to the container image.
COPY . .

# Set environment variables for production.
ENV NEXT_TELEMETRY_DISABLED 1
ENV PORT 3000

# Expose the port the app runs on.
EXPOSE 3000

# Build the application for production.
RUN npm run build

# Run the web service on container startup.
CMD [ "npm", "start" ]
CMD ["pm2-runtime", "start", "npm", "--", "start"]

0 comments on commit 3e4c6b7

Please sign in to comment.