forked from bramses/ycb-companion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
43 lines (30 loc) · 1.02 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Use the official Node.js 20 image as the base image
FROM node:20-alpine AS builder
# Set the working directory
WORKDIR /app
# Copy package.json and package-lock.json
COPY package.json package-lock.json ./
# Install dependencies
RUN npm ci
# Copy the rest of the application code
COPY . .
# Build the Next.js application
RUN npm run build
# Use a smaller base image for the final stage
FROM node:20-alpine AS runner
# Set the working directory
WORKDIR /app
# Copy package.json and package-lock.json first to leverage Docker cache
COPY --from=builder /app/package.json ./
COPY --from=builder /app/package-lock.json ./
# Install only production dependencies
RUN npm ci --only=production
# Copy the built application from the builder stage
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
# Copy the .env file last to avoid invalidating the cache for previous layers
COPY --from=builder /app/.env ./
# Expose the port the app runs on
EXPOSE 3000
# Start the Next.js application
CMD ["npm", "run", "start"]