A work in progress

As we have said earlier, currently we are working on the website as well as the user’s dashboard. As a part of this current stage, synced daemons are mandatory. We have installed and setted up 2…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




NodeJS and Containerization

In this series I will provide step-by-step instructions to port a fully functional application (that’s already in use BTW) to a containerized version, albeit with limited functionality. I am just sharing, since sharing is caring.

Caution: importing a data repository, mongoDB or mySQL, in a containerized environment requires some work. And I mean it’s not quick, so be forewarned. So if you want to create a containerized repository that your application containers can use, you got some work to do, I would say about 1–2 hrs. See instruction below.

In order to follow this series you need to have a good understanding of

I use a macBook High Sierra as my development environment.

TBH, I don’t think this really needs too much discussion since there are plenty of resources touting the benefits of this platform so I am not going to get into it. Except to say I like NodeJS, and JS for that matter. I have been coding and building applications in this environment for a while and I am pretty comfortable with NodeJS.

Monolithic applications are difficult to maintain, stack dependent, hard to update, slow to deploy, and often much more difficult to QA. Containerization, on the other hand, is a wonderful new way to write robust applications that could grow overtime without becoming monolithic. Instead of creating a large application that has all the API in a single point of entry, containers allow for multitude of services that constitute your application.

To understand software containers, it would be helpful to consider a similar example from the real world — shipping containers.

Software containers fulfill a similar role for an application. Packing the container involves defining what needs to be there for an application to work — operating system, libraries, configuration files, application itself, and other parts of your technology stack. Once a container has been defined (imaged), that image is used to create containers that run in any environment, from the developer’s laptop to test/QA servers, to the production data center, on-premises or in the cloud, without any changes.

Now that we are done with the niceties, let’s discuss the overall structure of our service. The services that I will design and develop will all have similar structure. This is how my service structure, first of many, looks like.

/home/{user}/github/{name of service}-services (top level)

Before we start diving into code there are a few preliminary tasks that we need to perform. Paramount would be to ensure you have a data repository to test your containerized application with. Let’s start by creating 3 virtual machines. These virtual machines will host the mongoDB replication set, as well as the application containers.

To see the creations run the command:

Output is a table of the virtual boxes. And to see the containers in each of these virtual boxes we need to run the below commands (the first command effectively logs you into a virtual machine -vbManager, vbWorker1, vbWorker2- to inspect the container is up and running):

vbManager is the primary (active) mongodb virtual server that handles the routing of requests to other servers, mainly vbWorker1 and vbWorker2.

If you need to stop the virtual boxes you can type:

So this key file is a shred password between the replica set.

This is a big task and requires multiple steps that best can be done by creating a shell script createReplicas.sh, which I have done, courtesy of Crizstian (many many thanks for your great work). resetDocker.sh will basically remove the containers mongoNode1..3, allowing you to recreate the containers by running createReplicas.sh in case something goes wrong.

The 2 above commands make the files executable so that you can call them by typing:

If you don’t want to make the files executable then you can type:

Get a dump of your data repository

Will produce a .gz file that you now must move to the volume that was created for your mongoNode containers. But you must make sure you are in the vbManager virtual box.

You now need to update thed CRUD permission for raykahn, the user with access to the database.

You should see the following on the command line:

And now import the mongodb database. But before that you need to change Login to the mongoDB server

Now login to your imported db to see that data was successfully imported

You are done with your mongodb database import.

Next blog will be about creating a service, a single service for now that connects to a mongodb using mongoose and returns some value.

Stay Tuned…

Add a comment

Related posts:

9 Tips on the Most Underestimated Skill in the Workplace

One of the most overlooked and underestimated skills at the workplace is the ability to write effective emails. I have easily written over 10,000 emails since I first started working in the corporate…

My Job

My job as a gymnastics coach is great. I love working with kids and helping them achieve their goals. Although it can be stressful at times, I wouldn’t trade my job for any other. Occasionally I will…

How ARAW token platform will protect merchants and customers from fraud?

Numerous existing issues and fraud techniques are affecting the E-Commerce and Payments industry, which has been the case for decades. Even with current software, privacy and data management…