-
-
Notifications
You must be signed in to change notification settings - Fork 303
node-gyp needs build tools #27
Comments
The idea of this docker image is to be as small as possible with a full node installation – for ppl who don't have native dependencies, it would add a lot of weight to include these. There's an example on the README for how to add them in your own Dockerfile if you need them for your project though: https://github.com/mhart/alpine-node#example-dockerfile-for-your-own-nodejs-project |
@mhart I'm fairly new to this, so I was wondering what is the purpose of installing In the official dockerfile it does not seem like Node requires it for installation. |
That Dockerfile doesn't need any build tools because it's not actually building node – it's just unpacking a prebuilt binary on debian. There's no prebuilt binary for Alpine, so we have to build it ourselves – hence all the build tools that need installing. They're then removed to keep the image size down – most ppl won't need them again – but if you do you can always reinstall them |
Sorry about posting on an old thread, but since Google lands here for this question, I'dd suggest doing the following if you have native dependencies:
This way the build dependencies don't end up in your Docker layers and thus keep the image size almost as small as if you didn't install those dependencies. |
Old thread, but because of google, still relevant :).
Or simpler, by using
|
Perhaps you could use docker multi-stage build and copy Sample Dockerfile: # Stage-1 dependencies
FROM node:latest as dep
RUN mkdir /sample
WORKDIR /sample
ADD package.json .
RUN ["npm", "i", "--only=production"]
# Stage-2 final image
FROM node:alpine
RUN mkdir /sample
WORKDIR /sample
COPY --from=dep /sample/node_modules ./node_modules
RUN ["npm", "rebuild", "-q"]
ADD . .
ENTRYPOINT [ "npm", "start" ] Hope this helps |
@AkashBabu Is the prefered way of handling deps moving forward. |
@thebetterjort Can you please elaborate your statement? |
@AkashBabu A workaround which is informally called the builder pattern involves using two Docker images - one to perform a build and another to ship the results of the first build without the penalty of the build-chain and tooling in the first image. Multi-stage builds give the benefits of the builder pattern without the hassle of maintaining three separate files: The prefered way of handling deps for the future of containers is multistage as it miitigates multiple Dockerfiles for different architectures." |
@thebetterjort @AkashBabu there's already an example of doing multistage builds in the README: https://github.com/mhart/alpine-node#example-dockerfile-for-your-own-nodejs-project (the second example) |
+1 for @mhart's answer |
Just a note for people still referring to this thread :
May throw some error
You have to specify the python version in some cases to avoid apk errors
or
|
node-gyp, which is often used by packages installed through npm (at least that is my experience), needs
python
,make
, andgcc
. Would it make sense not to clean those up? (Currently happening in line 36 of the Dockerfile)The text was updated successfully, but these errors were encountered: