multi stage build docker, to minimize the docker image file

This commit is contained in:
lth 2024-02-19 17:16:29 +01:00 committed by GitHub
parent 55299f001f
commit af70930be2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,23 +1,33 @@
FROM node:16-buster-slim
RUN apt-get update && \
apt-get install -y chromium traceroute && \
chmod 755 /usr/bin/chromium && \
rm -rf /var/lib/apt/lists/*
# Build stage
FROM node:16-buster-slim AS build
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install && \
RUN apt-get update && \
yarn install --production && \
rm -rf /app/node_modules/.cache
COPY . .
RUN yarn build
RUN yarn build --production
# Final stage
FROM node:16-buster-slim AS final
WORKDIR /app
COPY package.json yarn.lock ./
COPY --from=build /app .
RUN apt-get update && \
apt-get install -y --no-install-recommends chromium traceroute && \
chmod 755 /usr/bin/chromium && \
rm -rf /var/lib/apt/lists/* /app/node_modules/.cache
EXPOSE ${PORT:-3000}
ENV CHROME_PATH='/usr/bin/chromium'
CMD ["yarn", "serve"]
CMD ["yarn", "serve"]