From af70930be280459389fbc728a2d7405848c6d9d0 Mon Sep 17 00:00:00 2001 From: lth Date: Mon, 19 Feb 2024 17:16:29 +0100 Subject: [PATCH] multi stage build docker, to minimize the docker image file --- Dockerfile | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3951f553..3133050a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file +CMD ["yarn", "serve"]