forked from hoangsonww/ToDo-App-NextJS-Fullstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
45 lines (32 loc) · 1006 Bytes
/
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
44
45
# Stage 1: Build Stage
FROM node:18-alpine AS builder
# Set the working directory
WORKDIR /app
# Copy the package.json and package-lock.json/yarn.lock files
COPY package*.json yarn.lock ./
# Install dependencies
RUN yarn install --frozen-lockfile
# Copy the rest of the application code
COPY . .
# Build the Next.js app
RUN yarn build
# Stage 2: Production Stage
FROM node:18-alpine AS runner
# Set the working directory
WORKDIR /app
# Copy package.json and yarn.lock files for production
COPY package*.json yarn.lock ./
# Install only production dependencies
RUN yarn install --production --frozen-lockfile
# Copy built files from the build stage
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/package.json ./
# Expose port 3000
EXPOSE 3000
# Set environment variable
ENV NODE_ENV=production
# Start the Next.js app
CMD ["yarn", "start"]