Skip to content

Commit

Permalink
Update Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
BillChirico authored Nov 6, 2023
1 parent 193cd55 commit 0aa9569
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,32 @@

## Base ########################################################################
# Use a larger node image to do the build for native deps (e.g., gcc, python)
FROM node:lts as base

# We'll run the app as the `node` user, so put it in their home directory
WORKDIR /home/node/app
# Copy the source code over
COPY --chown=node:node . /home/node/app/

## Development #################################################################
# Define a development target that installs devDeps and runs in dev mode
FROM base as development
WORKDIR /home/node/app
# Install (not ci) with dependencies, and for Linux vs. Linux Musl (which we use for -alpine)
RUN npm install
# Switch to the node user vs. root
USER node
# Expose port 5000
FROM node:lts-alpine AS deps

WORKDIR /opt/app
# Copy package.json and package-lock.json to the working directory
COPY package.json package-lock.json ./
# Install production dependencies only
RUN npm ci --only=production

# Stage 2: Build the application
FROM node:lts-alpine AS builder

WORKDIR /opt/app
# Copy all files from the current directory to the working directory in the container
COPY . .
# Copy node_modules from the "deps" stage
COPY --from=deps /opt/app/node_modules ./node_modules
# Build the application
RUN npm run build

# Stage 3: Create the production image
FROM node:lts-alpine AS runner
# Set the working directory in the container to /opt/app
WORKDIR /opt/app
# Set environment variable
ENV NODE_ENV=production
# Copy necessary files from the "builder" stage
EXPOSE 5000
# Start the app in debug mode so we can attach the debugger
CMD ["npm", "serve"]
# Define the command to run the application
CMD ["sh", "-l", "-c", "npm run serve"]

0 comments on commit 0aa9569

Please sign in to comment.