Our great sponsors
-
Nest
A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
The full source code of this project can be found here.
Let's create a baseline Node.js app using the NestJS framework. We will create a simple demo app and containerize it with Docker. Afterward, we will apply a few techniques to improve the baseline setup and reduce our image size. Make sure you have the following installed to get started:
There are a lot of base Node.js images that you can choose from. These can be found on the official Docker Hub page of Node.js. In our initial Dockerfile, we've chosen the node:17 base image. This node:17 base image incorporates a lot of dependencies from the underlying OS that you most likely don't need. We can try to use the node:17-slim version and check if that fits our needs. This is the resulting Dockerfile:
It's no surprise that larger images will take up more space. On your local machine you might not notice it if you have a large storage drive. However, you're probably going to be using a CI/CD pipeline to build these Docker images and then publish them to a central repository like Docker Hub. Having larger images will impact you in two ways. It takes more time to transfer these images from the CI/CD pipeline to the repository. Having all these large images in the repository will also result in more costs to store them all. This is especially important for projects under active development.