Easy to use Dockerfile for your next Node.js Project

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.

A simple 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.

Cu,

Stefan

PS: Thanks Oliver for the inspiration for this article.

--

--

--

I am a Software Engineer from Austria 🇦🇹. I write about JavaScript, TypeScript, ReactJS and NodeJS. 📧 Weekly NL Series: https://newsletter.natterstefan.me

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Get the most out of your React Summit Remote Edition experience

Network Request on the Remote Debugger

Top 5 Best JavaScript Frameworks to Learn and Use in 2020

React: Controlled VS Uncontrolled Components

A note on numbers in Ethereum and Javascript

What I Learned Deploying a Poetry Dapp

Angular @ngrx/store Side-By-Side Code Comparison

JavaScript — Closures

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Stefan Natter

Stefan Natter

I am a Software Engineer from Austria 🇦🇹. I write about JavaScript, TypeScript, ReactJS and NodeJS. 📧 Weekly NL Series: https://newsletter.natterstefan.me

More from Medium

CICD Pipelines with React, AWS S3, Circleci

The merchant list problem: caching frequently-changing aggregate data.

Comparisons of Auth solutions

Creating a HTTP Server with NodeJS and logging requests with promised fs