Create Dockerfile
Browse files- Dockerfile +64 -0
Dockerfile
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# --- Stage 1: Builder ---
|
2 |
+
# Use a Node.js image suitable for building (includes build tools if needed)
|
3 |
+
FROM node:18-alpine AS builder
|
4 |
+
|
5 |
+
# Set working directory
|
6 |
+
WORKDIR /app
|
7 |
+
|
8 |
+
# Copy package.json and package-lock.json (or yarn.lock/pnpm-lock.yaml)
|
9 |
+
# Copying these separately allows Docker to cache this step if only code changes
|
10 |
+
COPY package.json ./
|
11 |
+
# If you are using yarn, uncomment the line below and comment out the npm line
|
12 |
+
# COPY yarn.lock ./
|
13 |
+
# If you are using pnpm, uncomment the line below and comment out the npm line
|
14 |
+
# COPY pnpm-lock.yaml ./
|
15 |
+
COPY package-lock.json ./ # Use package-lock.json if you use npm
|
16 |
+
|
17 |
+
|
18 |
+
# Install dependencies including devDependencies for the build
|
19 |
+
# Use --frozen-lockfile or --ci for deterministic builds if using npm or yarn v1
|
20 |
+
RUN npm ci # Or `yarn install --frozen-lockfile` or `pnpm install --frozen-lockfile`
|
21 |
+
|
22 |
+
|
23 |
+
# Copy the rest of the application code
|
24 |
+
COPY . .
|
25 |
+
|
26 |
+
# Build the Next.js application
|
27 |
+
# NEXT_TELEMETRY_DISABLED=1 disables Next.js telemetry during the build
|
28 |
+
RUN NEXT_TELEMETRY_DISABLED=1 npm run build
|
29 |
+
|
30 |
+
# --- Stage 2: Runner ---
|
31 |
+
# Use a smaller, production-focused Node.js image
|
32 |
+
FROM node:18-alpine AS runner
|
33 |
+
|
34 |
+
# Set working directory
|
35 |
+
WORKDIR /app
|
36 |
+
|
37 |
+
# Copy necessary files from the builder stage
|
38 |
+
# Copy production dependencies
|
39 |
+
COPY --from=builder /app/package.json ./
|
40 |
+
COPY --from=builder /app/node_modules ./node_modules
|
41 |
+
# Copy the build output (.next folder)
|
42 |
+
COPY --from=builder /app/.next ./.next
|
43 |
+
# Copy public assets
|
44 |
+
COPY --from=builder /app/public ./public
|
45 |
+
# Copy next.config.js if it exists
|
46 |
+
COPY --from=builder /app/next.config.js ./next.config.js
|
47 |
+
|
48 |
+
|
49 |
+
# Set the environment variable for the Next.js port (default is 3000)
|
50 |
+
# Hugging Face Spaces typically exposes port 7860 for Gradio/Streamlit/etc,
|
51 |
+
# but for general web apps (like Next.js via the static host option or if you set up a custom server),
|
52 |
+
# it might expose port 3000 by default when detecting a standard Next.js app.
|
53 |
+
# It's good practice to set this, but Spaces often handles port mapping.
|
54 |
+
ENV PORT 3000
|
55 |
+
|
56 |
+
|
57 |
+
# Expose the port the application will run on
|
58 |
+
EXPOSE 3000
|
59 |
+
|
60 |
+
# Disable Next.js telemetry at runtime
|
61 |
+
ENV NEXT_TELEMETRY_DISABLED 1
|
62 |
+
|
63 |
+
# Command to run the production Next.js server
|
64 |
+
CMD ["npm", "start"]
|