fix: reduce docs Docker image size by cleaning npm cache#1129
fix: reduce docs Docker image size by cleaning npm cache#1129haosenwang1018 wants to merge 1 commit intoMemMachine:mainfrom
Conversation
|
Thanks @haosenwang1018 . Please sign your commit(s). See CONTRIBUTING.md for instructions. As noted by Christian, starting with a Node image rather than a vanilla Alpine image helps reduce the final image, as does a multi-stage approach. Combining all suggestions should give us the smallest possible image. Is that something you want to tackle? This PR is a good start in that direction. |
…se image Signed-off-by: haosenwang1018 <haosenwang1018@users.noreply.github.com>
99622c4 to
ce5e8a6
Compare
|
Thanks for the feedback! I've updated the Dockerfile to use a multi-stage build with Note: I don't have a GPG key configured yet for the Changes in this update:
|
|
Thanks for the fast response. I'll test the new Docker to see what the result is. Should be able to get back to you next week. |
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #1110 by reducing the memmachine-docs Docker image size from ~1.12GB through implementing a multi-stage build pattern and cleaning up npm artifacts.
Changes:
- Migrated from
alpine:latestwith manual Node.js installation to officialnode:22-alpinebase image - Implemented multi-stage Docker build with a builder stage for installing Mintlify and a minimal final stage
- Added cleanup of npm cache and temporary files in the build stage to reduce layer size
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| FROM node:22-alpine AS builder | ||
|
|
||
| # Install Mintlify globally | ||
| RUN npm install -g mint | ||
| RUN npm install -g mint && \ | ||
| npm cache clean --force && \ | ||
| rm -rf /tmp/* /root/.npm | ||
|
|
||
| FROM node:22-alpine | ||
|
|
||
| # Copy only the global Mintlify installation from builder | ||
| COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules | ||
| COPY --from=builder /usr/local/bin/mint /usr/local/bin/mint |
There was a problem hiding this comment.
The multi-stage build approach should significantly reduce the image size, which addresses the issue. However, there doesn't appear to be any automated testing for the docs Docker container (the docs service isn't included in CI workflows).
It's important to manually verify that the built image works correctly before merging:
- Build the image:
docker build -t memmachine-docs:test docs/ - Run the container:
docker run -v $(pwd)/docs:/docs:ro -p 3000:3000 memmachine-docs:test - Verify that
mint devstarts successfully and the docs are accessible at http://localhost:3000 - Check the image size:
docker images memmachine-docs:test(should be significantly smaller than 1.12GB)
This manual verification is critical because the mint binary needs access to its node_modules dependencies, and we need to ensure the COPY operations preserve all necessary files and symlinks correctly.
There was a problem hiding this comment.
We will address automations after manual verification.
|
Hi @haosenwang1018 , Below is the manual verification with steps provided in above comment
The error is then explained by claude code: I tried several solutions but it seems this one works, the diff is Would you please help to check the suggested change and see if these could be valid fix? Many thanks! |
Addresses #1110
The
memmachine-docsDocker image is ~1.12GB, which is excessive for a documentation server. The main contributor is the npm cache and temp files left behind afternpm install -g mint.This fix cleans up
npm cache,/tmp, and~/.npmin the sameRUNlayer as the install, which should significantly reduce the final image size.