Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/BestPractices.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ FROM node:alpine as app
COPY --from=builder node_modules .
```

Note that this multistage pattern only produces a tree that works on the architecture the builder ran on.
Native addons are compiled or downloaded for that host, so `COPY --from=builder node_modules .` into a stage
built for a different architecture puts a mismatched binary in the image while the manifest still looks
correct, and the first `require()` of it fails with `invalid ELF header`. Under
`docker buildx build --platform linux/amd64,linux/arm64`, install or `npm rebuild` inside each platform's
stage instead of sharing one tree between them.

## Smaller images without npm/yarn

To remove npm and Yarn package managers, use a multi-stage build.
Expand Down
Loading