loading...
Cover image for Shrink docker node images

Shrink docker node images

rubiin profile image Rubin ・1 min read

Working with nodejs on docker made me realize how much node_modules play a part on determining the image build size. I first started with slim node image but as I was working with microservices thus dealing with multiple build images.Even switching at the cost of some node packages not working as supposed to didnt do much good.
Node

Luckily I found a niche tool call node-prune which does help in shrinking your node_module size thus reducing the overall image size.
node-prune is a small tool to prune unnecessary files from ./node_modules, such as markdown, typescript source files, and soon.
So I ended up building my own custom imagr with the tool in built.You can check it out at (tinynode)[github.com/rubiin/tinynode]. The usage is fairly simple and you could also look a sample in the readme.
Try it and let me know what you think

GitHub logo rubiin / tinynode

This node image contains an additional tool inside

tiny-node

This node image contains an additional tool inside (node-prune)[https://github.com/tj/node-prune] .node-prune is a small tool to prune unnecessary files from ./node_modules, such as markdown, typescript source files, and so on thus reducing the final image size.

Usage

FROM tiny-node:12.17.0-alpine

WORKDIR /usr/src/app
COPY package.json ./
COPY yarn.lock ./
RUN yarn install --production=true

# this does the trick
RUN node-prune






Discussion

pic
Editor guide