Docker Image for Lightweight Node.JS and PM2 on Alpine Linux

I recently changed my deployment workflow for Oystr to be containerized within a Docker image. This has greatly simplified my deployment workflow and, combined with the private NPM repository I configured using Sinopia, has greatly simplified my development process too as I have now re-factored all my code over the past week into a microservices architecture.

During the process of doing this, like many others, I’ve found that the base Ubuntu Docker image is pretty heavy compared to how much code I’m deploying. The base Ubuntu Docker Image is ~190MB and after deploying things like Node.JS this bloats quite a lot to something closer to ~500MB. For my development machine this isn’t a problem, but Oystr is hosted on top of SSD-based infrastructure in the cloud, and this space is considerably limited.

As I’m doing Oystr on a pretty tight budget, I can’t afford to be too wasteful with these kinds of resources. This led me to re-visit something I thought about a while ago, which is to host Node.JS on top of Alpine Linux, a very minimal Linux distribution. After a little searching I found that Irakli Nadareishvili had already done a basic version at https://github.com/inadarei/node-alpine which works great!

As he’s using runit and I’m wanting PM2 as my process manager, I decided to fork his project and make the necessary changes. While I was at it, I exposed the web port, a volume for mounting your Node.JS app to, and an environment variable for the name of the main Node.JS file to make configuring a PM2 based Node.JS application a little easier. The original image is around 58MB and with the changes I’ve made, it’s only grown to about 78MB! Definitely and improvement over the Ubuntu image I’ve been using to date.

If you’re looking for the Docker image or source, it can be found at the following addresses. I’ve changed the README.md to reflect the changes I’ve made to the original Dockerfile so hopefully you’ll be able to get a deployment up pretty quickly.

GitHub Source – https://github.com/chris-tomich/node-pm2-alpine
Docker Image – https://hub.docker.com/r/christomich/node-pm2-alpine/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s