



So we decided to use Docker slim (~100 MB), but we still keep in mind that we can build a new image on the base of alpine Linux for armv7.Īfter this step, our Dockerfile looked like: FROM node : 10 -slim Our armv7 and alpine are not supported for this one. We tried it, but it did not work for us because of the processor architecture on the target platform. alpine – That’s what I strongly recommend.Īlpine is the best choice for a base image – it is the smallest one (only 70 MB).It is easy to find on dockerhub, and there are few small sized images. Yes, we had a Layered Node.js image, but 600 MB was still unacceptable for us. The total size of our images was ~700 MB. Node modules that we do not need (We will talk about this in further steps).įrom here we have ~100 MB of Node modules and 600 MB of the only base image.At the time of writing the post, the official full Node Docker image size is 900 MB and 899 MB for node:10 – libraries and API setsThat’s why full Node.js image usually starts from 600 MB. Do not specify FROM node or FROM node: as your base image.Full Node.js image adds a significant number of tools, like:– source controls software, such as git and others.Here is an example of Dockerfile that we were using: FROM node : 10īuild via this Dockerfile looks acceptable, but there is much work to do: So let’s find out how to reduce the Docker image size in Node.js. The first thing that comes on mind when we do not think about optimization is using a standard image. Step 3: Compile your app to a single bundle using NCCīy the way, if you need help in implementing your project on the JS Node, not only in optimizing images, you can always contact us.Step 2: Get rid of unnecessary dependencies.Steps to Node.js Docker image optimization we will go through: Therefore, today, I would like to share our experience with you on how to optimize Node.js Docker images and go through all the steps from the starting point of our optimization to the point where we are now.

Our business task was to run as many Docker containers as possible on an embedded device (Raspberry Pi), the problem is that usually, standard Docker images have a really big size ~600 MB and the average size of our Node Docker images were reaching over than 700 MB. So, we run almost all of our projects through it. Docker is a software platform designed to make it easier to create, deploy, and run applications by using containers and is one of the most required and great technologies in the world of modern development.
