Create a Docker Image Containing a Node.js Application and Host it on Docker Hub

This is first part we will be “dockerizing” a simple node application and pushing the image to docker hub.

App structure will be simple and look like this.

app_structure

We will run a simple node server.

Dockerfile will have the following instructions to build our image.

Now to build our image using the instructions in our Dockerfile. In our terminal window we will run this command.

If everything checks out after running docker build then if you run docker images, you should see your newly created image.

docker_images

Now to push our newly created image to https://hub.docker.com/. You will need to create a repository and name it according to docker hub specs.

docker_push

Here is a link to the repo on docker hub.
https://hub.docker.com/r/aldomatic/nodedemo/

Fetching venues from Foursquare using Go

Third party packages used:

Nodes Forever Package Doesn’t Mean Forever!

I run most of my node apps on a droplet with DigitalOcean. Recently there was an issue and the droplet had to be restarted by them, but my app didn’t restart. This was a big issue for me and my client. I use Forever to run the app, but this only works if the app crashes and not when the server is rebooted.

The solution to this is to use an Upstart script. The one below is an example of one I use, as you can see its pretty small. The scripts can get rather complex and it all depends on your needs.

The scripts need to live in /etc/init/ directory and with a .conf file extension.

The script can be started by running sudo service appname start. 

© 2016 Aldo Lugo

Theme by Anders NorenUp ↑