Optimize Dockerfile with multi-stage build
Also: * Skips installing dev dependencies * Runs as non root
This commit is contained in:
parent
0ffbf5e895
commit
7d63cac3b9
1 changed files with 11 additions and 3 deletions
12
Dockerfile
12
Dockerfile
|
|
@ -1,16 +1,24 @@
|
||||||
FROM node:lts-alpine
|
FROM node:lts-alpine AS build
|
||||||
|
|
||||||
WORKDIR /app
|
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 your source
|
# Copy the rest of your source
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
FROM node:lts-alpine
|
||||||
|
|
||||||
RUN apk add --no-cache openssl
|
RUN apk add --no-cache openssl
|
||||||
|
|
||||||
|
USER node:node
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY --from=build /app .
|
||||||
|
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
Loading…
Add table
Add a link
Reference in a new issue