50 lines
1.0 KiB
Docker
50 lines
1.0 KiB
Docker
# ---------- STAGE 1: Build React Front End ----------
|
|
FROM node:18-alpine AS build
|
|
|
|
# Create app directory
|
|
WORKDIR /app
|
|
|
|
# Copy root package.json/package-lock.json
|
|
COPY package*.json ./
|
|
|
|
# Copy client folder's package.json/package-lock.json
|
|
COPY client/package*.json ./client/
|
|
|
|
# Install dependencies:
|
|
# 1) Install root dependencies (for server)
|
|
RUN npm install
|
|
|
|
# 2) Install client dependencies
|
|
WORKDIR /app/client
|
|
RUN npm install
|
|
|
|
# Copy the rest of the React client code
|
|
COPY client/ /app/client
|
|
|
|
# Build the React client
|
|
RUN npm run build
|
|
|
|
# ---------- STAGE 2: Final Image ----------
|
|
FROM node:18-alpine
|
|
|
|
# Create directory for your server
|
|
WORKDIR /app
|
|
|
|
# Copy root package.json/package-lock.json again
|
|
COPY package*.json ./
|
|
|
|
# Install server dependencies
|
|
RUN npm install
|
|
|
|
# Copy your server code
|
|
COPY server.js ./
|
|
|
|
# Copy the compiled React build from STAGE 1
|
|
COPY --from=build /app/client/build ./client/build
|
|
|
|
# We will serve on port 4000 (or your choice)
|
|
EXPOSE 4000
|
|
|
|
# Start the server
|
|
CMD [ "node", "server.js" ]
|