From 0957e0b3d4d1f07bc260043fc8d22bcf7cbff48b Mon Sep 17 00:00:00 2001 From: unsync <1211591+unsync@users.noreply.github.com> Date: Fri, 20 Dec 2024 07:58:13 +0100 Subject: [PATCH] feature/reduce docker image size using build stage --- Dockerfile | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 20cec8ec1..123fb9323 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Use the official Node.js runtime as a parent image -FROM node:20-alpine +FROM node:20-alpine AS build # Set the working directory in the container WORKDIR /app @@ -16,10 +16,21 @@ COPY . . # Build the application and clean up RUN npm run build \ && rm -rf node_modules \ -&& npm install --production +&& npm install --omit=dev + +# Use the official Node.js runtime as a parent image +FROM node:20-alpine + +# Set the working directory in the container +WORKDIR /app + +# Copy the build directory, node_modules, and package.json to the working directory +COPY --from=build /app/build /app/build +COPY --from=build /app/node_modules /app/node_modules +COPY --from=build /app/package.json /app/package.json # Expose port 8787 EXPOSE 8787 ENTRYPOINT ["npm"] -CMD ["run", "start:node"] \ No newline at end of file +CMD ["run", "start:node"]