Docker update
This commit is contained in:
35
DockerFile
35
DockerFile
@ -1,21 +1,22 @@
|
|||||||
# Stage 1: Build
|
# Stage 1: Build
|
||||||
FROM node:18-alpine AS builder
|
FROM node:18-alpine AS builder
|
||||||
|
|
||||||
# Set working directory
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy package files and install dependencies
|
# Copy package files
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json ./
|
||||||
RUN npm install --production
|
|
||||||
|
|
||||||
# Copy the rest of the app
|
# Install ALL dependencies (including dev dependencies for build)
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
# Copy source code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Pass build-time environment variable
|
# Build arguments
|
||||||
ARG NEXT_PUBLIC_API_URL
|
ARG NEXT_PUBLIC_API_URL
|
||||||
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
|
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
|
||||||
|
|
||||||
# Build the Next.js app
|
# Build the app
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 2: Run
|
# Stage 2: Run
|
||||||
@ -23,23 +24,19 @@ FROM node:18-alpine AS runner
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy built app from builder
|
# Set to production
|
||||||
COPY --from=builder /app/.next ./.next
|
ENV NODE_ENV=production
|
||||||
COPY --from=builder /app/public ./public
|
|
||||||
COPY --from=builder /app/package.json ./package.json
|
|
||||||
COPY --from=builder /app/package-lock.json ./package-lock.json
|
|
||||||
COPY --from=builder /app/next.config.js ./next.config.js
|
|
||||||
|
|
||||||
# Install only production dependencies
|
# Copy necessary files
|
||||||
RUN npm install --production
|
COPY --from=builder /app/public ./public
|
||||||
|
COPY --from=builder /app/.next/standalone ./
|
||||||
|
COPY --from=builder /app/.next/static ./.next/static
|
||||||
|
|
||||||
# Expose port
|
# Expose port
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Runtime environment variables
|
ENV PORT=3000
|
||||||
ENV NODE_ENV=production
|
ENV HOSTNAME="0.0.0.0"
|
||||||
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
|
|
||||||
ENV HOST=0.0.0.0
|
|
||||||
|
|
||||||
# Start the app
|
# Start the app
|
||||||
CMD ["npm", "start"]
|
CMD ["node", "server.js"]
|
||||||
@ -2,13 +2,15 @@ version: "3.9"
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
nextjs:
|
nextjs:
|
||||||
build: .
|
build:
|
||||||
|
context: .
|
||||||
|
args:
|
||||||
|
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL}
|
||||||
container_name: cmc_nextjs_pro
|
container_name: cmc_nextjs_pro
|
||||||
ports:
|
ports:
|
||||||
- "9012:3000"
|
- "9012:3000"
|
||||||
env_file:
|
environment:
|
||||||
- .env # <-- tell Docker to use the .env file
|
- NODE_ENV=production
|
||||||
|
- NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
# Remove the volumes - they overwrite your build!
|
||||||
- .:/app
|
|
||||||
- /app/node_modules
|
|
||||||
@ -1,6 +1,7 @@
|
|||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
|
|
||||||
/* config options here */
|
/* config options here */
|
||||||
images: {
|
images: {
|
||||||
remotePatterns: [
|
remotePatterns: [
|
||||||
@ -22,7 +23,7 @@ const nextConfig: NextConfig = {
|
|||||||
pathname: '/api/files/images/**',
|
pathname: '/api/files/images/**',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
domains: ['localhost'],
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user