Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +18 -30
Dockerfile
CHANGED
|
@@ -1,45 +1,33 @@
|
|
| 1 |
-
#
|
| 2 |
-
# Create a build environment
|
| 3 |
-
FROM node:22-alpine AS builder
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
WORKDIR /app
|
| 7 |
-
|
| 8 |
-
# Copy package files and install ALL dependencies (including devDependencies)
|
| 9 |
-
COPY package*.json ./
|
| 10 |
-
RUN npm install
|
| 11 |
-
|
| 12 |
-
# Copy the rest of the source code
|
| 13 |
-
COPY . .
|
| 14 |
-
|
| 15 |
-
# Build the application
|
| 16 |
-
# Use --no-cache to ensure a clean build
|
| 17 |
-
RUN npm run build --no-cache
|
| 18 |
-
|
| 19 |
-
# === Stage 2: Production ===
|
| 20 |
-
# Create a final, lean production image
|
| 21 |
FROM node:22-alpine
|
| 22 |
|
| 23 |
-
# Set working directory
|
| 24 |
WORKDIR /app
|
| 25 |
|
| 26 |
-
#
|
| 27 |
COPY package*.json ./
|
| 28 |
-
RUN npm install --omit=dev
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
-
# Expose the port
|
| 36 |
EXPOSE 7860
|
| 37 |
|
| 38 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
RUN chown -R node:node /app
|
| 40 |
|
| 41 |
-
# Switch to
|
| 42 |
USER node
|
| 43 |
|
| 44 |
-
#
|
| 45 |
CMD ["npm", "run", "start"]
|
|
|
|
| 1 |
+
# for deploying a Next.js application in a Docker container
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
# Use Node 22 as the base image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
FROM node:22-alpine
|
| 5 |
|
| 6 |
+
# Set the working directory inside the container
|
| 7 |
WORKDIR /app
|
| 8 |
|
| 9 |
+
# Copy package.json and package-lock.json
|
| 10 |
COPY package*.json ./
|
|
|
|
| 11 |
|
| 12 |
+
# Install dependencies
|
| 13 |
+
RUN npm install
|
| 14 |
+
|
| 15 |
+
# Copy the rest of the application code
|
| 16 |
+
COPY . .
|
| 17 |
|
| 18 |
+
# Expose the port your app runs on
|
| 19 |
EXPOSE 7860
|
| 20 |
|
| 21 |
+
# --- FIX IS HERE ---
|
| 22 |
+
# Build the application. This runs during the `docker build` command.
|
| 23 |
+
RUN npm run build
|
| 24 |
+
|
| 25 |
+
# Change ownership of /app to the node user
|
| 26 |
+
# Do this *after* all root operations (like npm install/build) are done
|
| 27 |
RUN chown -R node:node /app
|
| 28 |
|
| 29 |
+
# Switch to a non-root user for better security
|
| 30 |
USER node
|
| 31 |
|
| 32 |
+
# Command to run the application when the container starts
|
| 33 |
CMD ["npm", "run", "start"]
|