DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Setting Apache Nifi on Docker Containers
  • How To Use the Node Docker Official Image
  • 7 Ways of Containerizing Your Node.js Application
  • Keep Your Application Secrets Secret

Trending

  • Deploy Like a Pro: Mastering the Best Practices for Code Deployment
  • SAP Business One vs. NetSuite: Comparison and Contrast of ERP Platforms
  • Three Ways AI Is Reshaping DevSecOps
  • Automate Your Quarkus Deployment Using Ansible
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Docker-Based MEAN.JS w/ Mongo Replica Set Automation on Any Cloud

Docker-Based MEAN.JS w/ Mongo Replica Set Automation on Any Cloud

DCHQ simplifies the containerization of applications and makes it possible to replicate very complex application environments on multiple hosts through a one-click deploy button.

Amjad Afanah user avatar by
Amjad Afanah
·
Sep. 16, 15 · Tutorial
Like (6)
Save
Tweet
Share
4.80K Views

Join the DZone community and get the full member experience.

Join For Free

A user who signed up to try DCHQ.io Hosted PaaS a couple of days ago asked me if we had an out-of-box template for MEAN.JS. So I told him that we’ll build a basic template for him before checking if there were any official images on Docker Hub.

Luckily, I came across the MEAN.JS official GitHub project, which had a Dockerfile and a Docker Compose template. So I went ahead and modeled the template on DCHQ and connected the Node.js container to a Mongo Replica Set. Here are the key advantages in the DCHQ app model:

  • The Mongo Replica Set and the Node containers can run on different hosts in order to comply with affinity rules. This is possible because of our integration with Weave and the host parameter that we have introduced to the Docker Compose app template.
  • The container IP for Mongo’s primary node is resolved dynamically at request time and is used in configuring the development.js file on the Node.JS container. This avoids container name conflicts if a compute resource is shared with many developers.
  • A BASH script plug-in is used to configure the Mongo Replica Set on the primary node using the container IP’s of the secondary nodes that are resolved at request time.

DCHQ simplifies the containerization of applications and makes it possible to replicate very complex application environments on multiple hosts through a one-click deploy button. DCHQ does not just automate the application deployments, but it also integrates with 12 different cloud providers to automate the provisioning and auto-scaling of Weave-enabled clusters consisting of distributed virtual machines.

In this blog, we will go over the deployment automation of a Docker-based MEAN.JS stack that’s connected to a Mongo Replica Set.

First, we’re going to build the Node.js image of the MEAN.JS stack by navigating to the Builds section and then clicking on the + button to select Git. The required fields here are:

  • Git URL of a project that has a Dockerfile and all the associate artifacts. In this case, we’re using the official MEAN.JS project (https://github.com/meanjs/mean) 
  • Cluster to be used for creating the image. The DCHQ agent automates the build or Docker image creation on one of the hosts in the cluster.
  • Registry for pushing the new image. This can be registered by navigating to Manage > Repo & Cloud Provider. A user can register his/her account with Docker Hub in order to start pushing to his private or public repositories.
  • The actual repository name
  • The tag for the new image (e.g. latest)
  • (Optionally) A cron expression can be provided to schedule the creation of images from this Git project.

Picture

Once the image has been pushed to your repository, then we’ll navigate to Manage > Templates to create the application template for the MEAN.JS stack.  Here are the key things to notice in this template:

  • The Node.js image is being pulled from the newly created image that we pushed to dchq/mean
  • We’re invoking a BASH script plug-in in the Node.js container to add the following line in development.js file at request time – uri: 'mongodb://$MONGO_IP/mean-dev',
  • You will notice that $MONGO_IP is resolving the container IP of the primary Mongo node at request time as indicated by the environment variable MONGO_IP={{mongo_rs1_srv1 | container_ip}}
  • The primary node of the Mongo Replica Set (mongo_rs1_srv1) is invoking a BASH script plug-in to initialize the replica set using the container IP’s of the secondary nodes that are resolved at request time.

Additionally, the host parameter allows you to specify the host you would like to use for container deployments. In this example, we split out all the containers of Node.js and the Mongo Replica Set on different hosts. Here are the values supported for the host parameter:

  • host1, host2, host3, etc. – selects a host randomly within a data-center (or cluster) for container deployments
  • <IP Address 1, IP Address 2, etc.> -- allows a user to specify the actual IP addresses to use for container deployments
  • <Hostname 1, Hostname 2, etc.> -- allows a user to specify the actual hostnames to use for container deployments
  • Wildcards (e.g. “db-*”, or “app-srv-*”) – to specify the wildcards to use within a hostname

Picture

A user can deploy this application by navigating to the Self-Service Library and then clicking on Run to deploy the application on the user’s default cluster (or data center). The default cluster needs to be Weave-enabled in order to facilitate the cross-container communication across different hosts.

Picture

You will notice that the Node.js (or MEAN.JS) container is running on one host while the Mongo Replica Set containers are running on another host. The Mongo Replica Set container ports are not exposed on the host. The Node.js container however is exposing port 3000 on the host using port 32779.

Once the application is up and running, a user can monitor the CPU, Memory, & I/O Utilization of the running containers and perform day-2 operations like Backup, Container Updates using BASH plug-ins, Scale In/Out and Continuous Delivery.

Picture

Picture

Alerts and notifications are available for when containers or hosts are down or when the CPU & Memory Utilization of either hosts or containers exceed a defined threshold.


Picture

Sign Up for FREE on DCHQ.io Hosted PaaS  (http://dchq.io) to get this template along with other templates like Java, PHP, Ruby, Python, and many others.

Docker (software) Host (Unix) Cloud application Template Node.js

Published at DZone with permission of Amjad Afanah, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Setting Apache Nifi on Docker Containers
  • How To Use the Node Docker Official Image
  • 7 Ways of Containerizing Your Node.js Application
  • Keep Your Application Secrets Secret

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: