Optimize Dockerfile with multi-stage build
This commit is contained in:
parent
57d962ae89
commit
da7809fd75
1 changed files with 20 additions and 6 deletions
26
Dockerfile
26
Dockerfile
|
|
@ -1,15 +1,29 @@
|
||||||
FROM node:lts-alpine
|
FROM node:lts-alpine AS build
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
RUN apk add --no-cache openssl
|
RUN apk add --no-cache openssl
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy only package files and install deps
|
# Copy only package files and install deps
|
||||||
# This layer will be cached as long as package*.json don't change
|
# This layer will be cached as long as package*.json don't change
|
||||||
COPY package*.json package-lock.json* ./
|
COPY package*.json package-lock.json* ./
|
||||||
RUN npm ci
|
RUN --mount=type=cache,target=/root/.npm npm ci --omit=dev
|
||||||
|
|
||||||
# Copy the rest of the source
|
# Copy the rest of your source
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
EXPOSE 8080
|
# Pre-generate prisma client
|
||||||
|
RUN node_modules/.bin/prisma generate
|
||||||
|
|
||||||
|
FROM node:lts-alpine
|
||||||
|
|
||||||
|
RUN apk add --no-cache openssl
|
||||||
|
|
||||||
|
USER node:node
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY --from=build --chown=node:node /app .
|
||||||
|
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue