DEV Community

Cover image for Shrink docker node images
Rubin
Rubin

Posted on

Shrink docker node images

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

tinynode

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:16.16.0-alpine

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

# this does the trick
RUN node-prune



Enter fullscreen mode Exit fullscreen mode

Dockerhub

Link to dockerhub

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT




Top comments (0)