set dockerfile

This commit is contained in:
2025-06-30 17:13:29 +03:30
parent c1c13a178e
commit 29e2ba9bd7
2 changed files with 52 additions and 24 deletions
+17 -5
View File
@@ -1,11 +1,23 @@
# docker-compose.yml
version: '3.8'
version: "3.8"
services:
react-app:
build: .
frontend:
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:
- "3000:80" # Changed host port
- "3001:3000"
environment:
- 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
View File
@@ -1,32 +1,48 @@
# Build stage
FROM node:22-alpine AS builder
# Dockerfile for Next.js 14 - Optimized for Production
# 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
# Install system dependencies (if needed)
RUN apk add --no-cache python3 make g++
# Copy package files
# Copy package.json and package-lock.json (or yarn.lock)
COPY package*.json ./
# Install dependencies
RUN npm npm i --force
# Install dependencies - leveraging Docker cache
RUN npm i --force
# Copy source code
# Copy the rest of the application code
COPY . .
# Build React app
# Build the Next.js application
RUN npm run build
# Production stage
FROM nginx:1.25-alpine
# Stage 2: Production image - smaller and leaner
FROM node:22-alpine AS runner
# Copy nginx config
COPY docker/nginx/nginx.conf /etc/nginx/conf.d/default.conf
# Set the working directory
WORKDIR /app
# Copy build artifacts
COPY --from=builder /app/build /usr/share/nginx/html
# Set environment variables
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
# Expose and run
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
# Add a non-root user for security
RUN addgroup -g 1001 -S nodejs
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"]