Improve docker file (#1)
Reviewed-on: http://git.sothink.vn/tungdt/cosmos-prototype-application/pulls/1
This commit was merged in pull request #1.
This commit is contained in:
39
Dockerfile
39
Dockerfile
@@ -1,39 +1,32 @@
|
||||
# Base image
|
||||
FROM node:22-alpine AS builder
|
||||
# Stage 1: Build
|
||||
FROM node:18-slim AS builder
|
||||
|
||||
ARG NODE_ENV=production
|
||||
ARG MONGODB_URI
|
||||
ARG MONGODB_DB
|
||||
|
||||
# Create app directory
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
COPY package.json package-lock.json* ./
|
||||
RUN npm ci
|
||||
# Copy dependencies first to cache better
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm install
|
||||
|
||||
# Copy the rest of the application
|
||||
# Copy all source code
|
||||
COPY . .
|
||||
|
||||
# Build the app
|
||||
# Build the Next.js app
|
||||
RUN npm run build
|
||||
|
||||
# Production image
|
||||
FROM node:22-alpine AS runner
|
||||
|
||||
# Stage 2: Run production image
|
||||
FROM node:18-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy only necessary files
|
||||
COPY --from=builder /app/package.json ./
|
||||
COPY --from=builder /app/package.json /app/package-lock.json ./
|
||||
RUN npm install --omit=dev
|
||||
|
||||
COPY --from=builder /app/.next .next
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/public public
|
||||
COPY --from=builder /app/next.config.ts ./
|
||||
COPY --from=builder /app/src src
|
||||
|
||||
# Set environment variables (optional)
|
||||
|
||||
# Expose port
|
||||
EXPOSE 3000
|
||||
|
||||
# Start the application
|
||||
CMD ["npm", "start"]
|
||||
CMD ["npx", "next", "start"]
|
||||
|
||||
Reference in New Issue
Block a user