diff --git a/docs/BestPractices.md b/docs/BestPractices.md index 58217745fe..563b21e087 100644 --- a/docs/BestPractices.md +++ b/docs/BestPractices.md @@ -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.