Florin Bobiș commited on
Commit
0d6f941
1 Parent(s): 3d9ac93

multistage docker

Browse files
Files changed (1) hide show
  1. Dockerfile +12 -14
Dockerfile CHANGED
@@ -1,23 +1,21 @@
1
- # Use an official Node.js runtime as the base image
2
- FROM node:18-alpine
3
-
4
- # Set the working directory in the container
5
  WORKDIR /app
6
-
7
- # Copy package.json and package-lock.json to the working directory
8
  COPY package*.json ./
9
-
10
- # Install project dependencies
11
  RUN npm install
12
-
13
- # Copy all source files to the working directory
14
  COPY . .
15
-
16
- # Build the Next.js application
17
  RUN npm run build
18
 
19
  # Expose the port your app runs on
20
  EXPOSE 7860
21
 
22
- # Define the command to run your app
23
- CMD [ "npm", "start" ]
 
 
 
 
 
 
 
 
 
1
+ # Stage 1: Build
2
+ FROM node:latest AS builder
 
 
3
  WORKDIR /app
 
 
4
  COPY package*.json ./
 
 
5
  RUN npm install
 
 
6
  COPY . .
 
 
7
  RUN npm run build
8
 
9
  # Expose the port your app runs on
10
  EXPOSE 7860
11
 
12
+ # Stage 2: Serve
13
+ FROM node:alpine
14
+ WORKDIR /app
15
+ COPY --from=builder /app/.next ./.next
16
+ COPY --from=builder /app/public ./public
17
+ COPY --from=builder /app/package.json ./package.json
18
+
19
+ RUN npm install next
20
+
21
+ CMD ["npm", "start"]