Docker has made our lives as developers easier. With just a few commands, we can start all kinds of programs and services without having to deal with the tedious installation of dependencies. Countless Docker images are freely available on Docker Hub. Whether you want to start your own open-source continuous integration & deployment server, such as Strider, or your own NPM registry with verdaccio.org, the possibilities are endless.
But these are mostly ready-made Docker images I was talking about. But for your own projects, you have to build your own Docker image. And in this article, I will show and describe in a few words how you can put your next NodeJS application into a Docker image. Here we go.
Dockerfile looks something like this:
But what if you need to build the app first before you can run it? Let’s take a look at this by using a multi-stage build.
This is it. You now have the option to choose between a multi-stage or a single-stage Dockerfile for your next project. Of course, we could optimize some things still and apply different approaches, but that’s maybe part of another story of my #90DaysOfProse challenge.
PS: Thanks Oliver for the inspiration for this article.