Docker & Nodejs – Part I – Creating A Docker Ready Nodejs App

What I like in Docker is its simplicity, once you master how to use it, developing and running applications becomes simpler. In this serie of tutorial I am using Docker Compose to create a container for a Nodejs application.

Let’s start by creating a sample app:

Let’s start by using Node image to run into the Docker container :

Create a file called

and add

By the code above we would like to use nodesource/node:4.0 image from the official Docker repository and we mounted the application source files to

which is the Node app root directory.

Let’s try to create the machine:

You will certainly have errors similar to the next ones:

To execute the Node app we should run:

and to keep the container running without exiting we should add an infinite loop and that’s why I added a script

Let’s add the script as an entrypoint to the Docker container

If you are having some problems, think about running

on the files that should be executed (main.js & start.sh).

Finally run

I will be posting other related posts (Docker + NodeJS ..etc) so wait for the Part II.

Happy Hacking !

You may also like...