set dockerfile
This commit is contained in:
+17
-5
@@ -1,11 +1,23 @@
|
|||||||
# docker-compose.yml
|
# docker-compose.yml
|
||||||
version: '3.8'
|
version: "3.8"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
react-app:
|
frontend:
|
||||||
build: .
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
args:
|
||||||
|
- NODE_ENV=production
|
||||||
|
- NEXT_TELEMETRY_DISABLED=1
|
||||||
|
- NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
|
||||||
|
- NEXT_PUBLIC_CLIENT_ID=${NEXT_PUBLIC_CLIENT_ID}
|
||||||
|
- NEXT_PUBLIC_CLIENT_SECRET=${NEXT_PUBLIC_CLIENT_SECRET}
|
||||||
|
restart: unless-stopped
|
||||||
|
container_name: nobat724-frontend
|
||||||
ports:
|
ports:
|
||||||
- "3000:80" # Changed host port
|
- "3001:3000"
|
||||||
environment:
|
environment:
|
||||||
- NODE_ENV=production
|
- NODE_ENV=production
|
||||||
restart: unless-stopped
|
- NEXT_TELEMETRY_DISABLED=1
|
||||||
|
- NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
|
||||||
|
- NEXT_PUBLIC_CLIENT_ID=${NEXT_PUBLIC_CLIENT_ID}
|
||||||
+35
-19
@@ -1,32 +1,48 @@
|
|||||||
# Build stage
|
# Dockerfile for Next.js 14 - Optimized for Production
|
||||||
FROM node:22-alpine AS builder
|
|
||||||
|
|
||||||
|
# Use the official Node.js image with Alpine Linux for a smaller footprint
|
||||||
|
FROM node:22-alpine AS base
|
||||||
|
|
||||||
|
# Set the working directory in the container
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install system dependencies (if needed)
|
# Copy package.json and package-lock.json (or yarn.lock)
|
||||||
RUN apk add --no-cache python3 make g++
|
|
||||||
|
|
||||||
# Copy package files
|
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies - leveraging Docker cache
|
||||||
RUN npm npm i --force
|
RUN npm i --force
|
||||||
|
|
||||||
# Copy source code
|
# Copy the rest of the application code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build React app
|
# Build the Next.js application
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Production stage
|
# Stage 2: Production image - smaller and leaner
|
||||||
FROM nginx:1.25-alpine
|
FROM node:22-alpine AS runner
|
||||||
|
|
||||||
# Copy nginx config
|
# Set the working directory
|
||||||
COPY docker/nginx/nginx.conf /etc/nginx/conf.d/default.conf
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy build artifacts
|
# Set environment variables
|
||||||
COPY --from=builder /app/build /usr/share/nginx/html
|
ENV NODE_ENV production
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
|
|
||||||
# Expose and run
|
# Add a non-root user for security
|
||||||
EXPOSE 80
|
RUN addgroup -g 1001 -S nodejs
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
RUN adduser -S nextjs -u 1001
|
||||||
|
|
||||||
|
# Copy only the necessary files from the builder stage
|
||||||
|
COPY --from=base /app/next.config.js ./
|
||||||
|
COPY --from=base /app/public ./public
|
||||||
|
COPY --from=base --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
|
COPY --from=base --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
|
# Change ownership of all copied files to the non-root user
|
||||||
|
USER nextjs
|
||||||
|
|
||||||
|
# Expose the port Next.js listens on
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Command to start the Next.js server in production mode
|
||||||
|
CMD ["node", "server.js"]
|
||||||
Reference in New Issue
Block a user