Reducing a node application’s Docker image size from 2.4GB to less than 100MB. Learning Docker step by step

Hi folks!

I'm all new to Reddit, and since I had some fun learning Docker lately I thought it'd be fun to join the community here :).

I wrote a 2 part blog post about my journey reducing the size of the Docker image of a [well known]( nodejs application as much as I could. I managed to go down to 100MB, from a starting point of 2.43GB when doing it 'quick and dirty'.

[Maybe some of you like it!](

And if you have more advice, please enlighten me! As mentioned, I am learning in the process.


12 thoughts on “Reducing a node application’s Docker image size from 2.4GB to less than 100MB. Learning Docker step by step”

  1. If you are serving a static site, you could use as a second stage image a nginx (could be nginx-alpine to reduce size) image, and serve with nginx the statics. There’s no need to have running a “heavy” node server.

  2. Did something similar recently. Node alpine and I copy over an entrypoint shell script and a single bundled file of my node app, was around 100 or so MB total. I don’t copy over all the node nodules.

  3. Awesome blog post!

    I created a docker-slim example for the app too. It has a very basic Dockerfile version using the standard node image without multi-stage and without other optimizations resulting in an image that’s 2GB+. The optimized image is 93MB:

    By the way, the xray command in docker-slim will give you something similar to what you get with Dive (no interactive shell though for now though).

  4. I’m a bit curious, what is the difference with using `mhart/alpine-node` vs using the ~~actual~~ official `node:alpine` ? I’ve been looking through the 2 dockerfiles but can’t really see the difference 🙁

    (Assuming we’re using the same Node LTS version 12.17.0)

  5. Love the article. For the life of me i can’t understand something tho: how does splitting it into builder/runner containers save space? It looks like you are installing and building everything into /app in the builder and then copying everything in /app into the second container. Since the base alpine image is the same, i can’t see what space is being saved from the builder container. (Sorry if i’m missing something obvious!)


Leave a Comment