Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] Minimize size of docker image #587

Open
SimonSimCity opened this issue Oct 18, 2024 · 0 comments
Open

[doc] Minimize size of docker image #587

SimonSimCity opened this issue Oct 18, 2024 · 0 comments

Comments

@SimonSimCity
Copy link

I was looking a bit into https://pnpm.io/docker and was wondering if not the image could be made smaller by leaving out the app code.

The first docker-file would be changed as following:

diff --git forkSrcPrefix/backend/Dockerfile forkDstPrefix/backend/Dockerfile
index b04e176fef6ca3f709e2db8149f867d003a5c4db..a1ce67142ccf1a33ae1cffc1b5b6a891da449730 100644
--- forkSrcPrefix/backend/Dockerfile
+++ forkDstPrefix/backend/Dockerfile
@@ -1,6 +1,4 @@
-ARG NODE_VERSION=UNDEFINED
-
-FROM node:${NODE_VERSION}-slim AS base
+FROM node:20-slim AS base
 ENV PNPM_HOME="/pnpm"
 ENV PATH="$PNPM_HOME:$PATH"
 RUN corepack enable
@@ -14,8 +12,8 @@ FROM base AS build
 RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
 RUN pnpm run build
 
-FROM node:${NODE_VERSION}-slim
+FROM base
 COPY --from=prod-deps /app/node_modules /app/node_modules
 COPY --from=build /app/dist /app/dist
 EXPOSE 8000
-CMD [ "npm", "start" ]
+CMD [ "pnpm", "start" ]

The reason for this is that you do not get things that come along with running corepack, the app code, and for the start-command likely can be run via npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant