Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    Interview

    Interview with Anuar Akhmetov: I Was Apathetic of Programming until I Met My Very Best Mentor

    Remote Job

    How to Make Remote Work More Effective?

    JavaScript

    Monthly Digest of the Most Popular and Trending JS GitHub Repos

    Important Pages:
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Today's Picks:
    • Scaling Success: Monitoring Indexation of Programmatic SEO Content
    • Leveraging Influencers: Key Drivers in New Product Launches
    • How Privacy-First Marketing Will Transform the Industry Landscape
    • The Impact of Social Proof on Thought Leadership Marketing
    • Balancing Value-Driven Content and Promotional Messaging Strategies
    • Top Influencer Marketing Platforms to Explore in 2025
    • Emerging Trends in Marketing Automation and AI Tools for 2023
    • Strategies to Mitigate Duplicate Content in Programmatic SEO
    Wednesday, September 10
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Soshace Digital Blog
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Services
    • SaaS & Tech

      Maximizing Efficiency: How SaaS Lowers IT Infrastructure Costs

      August 27, 2025

      Navigating Tomorrow: Innovations Shaping the Future of SaaS

      August 27, 2025

      Maximizing Impact: Strategies for SaaS & Technology Marketing

      August 27, 2025
    • AI & Automation

      Enhancing Customer Feedback Analysis Through AI Innovations

      August 27, 2025

      Navigating the Impact of AI on SEO and Search Rankings

      August 27, 2025

      5 Automation Hacks Every Home Service Business Needs to Know

      May 3, 2025
    • Finance & Fintech

      Critical Missteps in Finance Marketing: What to Avoid

      August 27, 2025

      Analyzing Future Fintech Marketing Trends: Insights Ahead

      August 27, 2025

      Navigating the Complex Landscape of Finance and Fintech Marketing

      August 27, 2025
    • Legal & Compliance

      Exploring Thought Leadership’s Impact on Legal Marketing

      August 27, 2025

      Maximizing LinkedIn: Strategies for Legal and Compliance Marketing

      August 27, 2025

      Why Transparency Matters in Legal Advertising Practices

      August 27, 2025
    • Medical Marketing

      Enhancing Online Reputation Management in Hospitals: A Guide

      August 27, 2025

      Analyzing Emerging Trends in Health and Medical Marketing

      August 27, 2025

      Exploring Innovative Content Ideas for Wellness Blogs and Clinics

      August 27, 2025
    • E-commerce & Retail

      Strategic Seasonal Campaign Concepts for Online and Retail Markets

      August 27, 2025

      Emerging Trends in E-commerce and Retail Marketing Strategies

      August 27, 2025

      Maximizing Revenue: The Advantages of Affiliate Marketing for E-Commerce

      August 27, 2025
    • Influencer & Community

      Leveraging Influencers: Key Drivers in New Product Launches

      August 27, 2025

      Top Influencer Marketing Platforms to Explore in 2025

      August 27, 2025

      Key Strategies for Successful Influencer Partnership Negotiations

      August 27, 2025
    • Content & Leadership

      The Impact of Social Proof on Thought Leadership Marketing

      August 27, 2025

      Balancing Value-Driven Content and Promotional Messaging Strategies

      August 27, 2025

      Analyzing Storytelling’s Impact on Content Marketing Effectiveness

      August 27, 2025
    • SEO & Analytics

      Scaling Success: Monitoring Indexation of Programmatic SEO Content

      August 27, 2025

      Strategies to Mitigate Duplicate Content in Programmatic SEO

      August 27, 2025

      Effective Data Visualization Techniques for SEO Reporting

      August 27, 2025
    • Marketing Trends

      How Privacy-First Marketing Will Transform the Industry Landscape

      August 27, 2025

      Emerging Trends in Marketing Automation and AI Tools for 2023

      August 27, 2025

      Maximizing ROI: Key Trends in Paid Social Advertising

      August 27, 2025
    Soshace Digital Blog
    Blog / JavaScript / Node.js / Dockerization of Node.JS Applications on Amazon Elastic Containers
    Node.js

    Dockerization of Node.JS Applications on Amazon Elastic Containers

    Muhammad BilalBy Muhammad BilalFebruary 7, 2020Updated:October 20, 2020No Comments11 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Dockerization of Node.JS Applications on Amazon Elastic Containers
    Dockerization of NodeJS Applications on Amazon Elastic Containers
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    Dockerization of NodeJS Applications on Amazon Elastic Containers
    Dockerization of NodeJS Applications on Amazon Elastic Containers
    Number of users in millions
    Number of users in millions

    The Internet has grown exponentially within the past decade. As of October 2019, according to statistics, 4.48 billion people around the world were active internet users. This phenomenon demands highly scalable services that are fail-free and consume the minimum of resources when running because all things in the cloud come at a cost. This article is about creating a critical task-based highly available and scalable NodeJS application on the Amazon Cloud with an architecture that minimizes its cost.

    At the end of this article you should have learned about:

    • Dockerization of a Local Node Application
    • Building and Uploading a Docker Image
    • Running a Docker Container Locally
    • Dockerization of a Node Application on AWS
    • Creating Elastic Container Registries
    • Clustering on ECS and Running it as a Service

    Prerequisites

    To keep things productive, the initial installation of the following will be required. Almost all of those listed below are automated installers, therefore this shouldn’t be a hassle.

    • Node and NPM
    • AWS CLI
    • Docker

    NodeJS Boilerplate Application

    Let’s start by cloning the boilerplate code, which I have written for a NodeJS Application
    https://github.com/th3n00bc0d3r/NodeJS-Boilerplate

    git clone https://github.com/th3n00bc0d3r/NodeJS-Boilerplate 
    cd NodeJS-Boilerplate
    npm i
    node app.js
    Listening: 3000

    The boilerplate code will give a base web server using express.js listening at port 3000 for two requests.

    • An HTTP response request at http://localhost:3000/
    • An HTTP Get request with a JSON Response at http://localhost/:3000/test

    Dockerizing the Boilerplate Application

    Docker is an open-source software giving you the ability to create an environment inside a container that makes sure all dependencies of your application are packed together for it to run flawlessly. This ensures that the container, which becomes a container image, runs independently of any hardware specifications or platform restrictions, which, in turn, might run well on a Linux machine, but when executed on a Windows machine, fail miserably due to its library and environment path dependencies. It also solves the problem of sharing a code with someone where, in most cases, the environments of both computers are set differently.

    The Dockerfile

    A dockerfile is a set of instructions that assist docker to configure and create a container image of your application. To create a docker file just go into the boilerplate application directory and create a file by the name of Dockerfile – case sensitive.

    touch Dockerfile
    Dockerfile
    Dockerfile

    Contents of our Dockerfile

    FROM node:6-alpine
    RUN mkdir -p /usr/src/app
    WORKDIR /usr/src/app
    COPY . .
    RUN npm install
    EXPOSE 3000
    CMD [ "node", "app.js" ]

    Let’s go through those lines one by one for clarity of the structure of the dockerfile.

    FROM node:6-alpine

    All dockerfiles start with the very first line of the file which is known as the base image. A base image is a starting point for your docker container. A base image can be a stripped-down version of Ubuntu or CentOS so that your application can have a dedicated environment. The docker base image acts as layers, and you can pour one layer on top of another and when it compiles, the compiled docker image itself can be used as a base image for some other application. Docker has a Docker Hub which is a cloud-based repository, a collection of distributed container images created by users like you and me. You can explore and access Docker Hub at http://hub.docker.com/

    We are using our base image from the following URL: https://hub.docker.com/_/node/

    To translate the first line of our docker file in general terms we can refer to the following image.

    Translating the first line of the docker file
    Translating the first line
    RUN mkdir -p /usr/src/app

    The RUN identifier allows us to execute a command. In this case, we are using the mkdir command to create a directory in /usr/src/app which will complete the code of our NodeJS Boilerplate application.

    WORKDIR /usr/src/app
    COPY . .
    RUN npm install

    In this set of code, WORKDIR is setting up an environmental path to be used internally by the docker container image itself. It sets our working directory. Once our working directory is set, we copy our Node Application files to that directory using the COPY command, and then, using the RUN identifier, execute the node_modules initialization process.

    EXPOSE 3000

    The last line is the command for our node application to start. It is a way of telling docker how to run our application.

    Read More:  Mastering JavaScript Proxies: Practical Use Cases and Real-World Applications

    We are now ready to build over the docker image.

    NOTE: Make sure that, at this point, you have the docker running. You should have the docker installed using the installer and then opened it. It should be in your taskbar.

    Docker Desktop is up and running
    Docker Desktop is up and running

    Building the Docker Image

    To build a docker image, execute the following command in the NodeJS Application directory.

    docker build -t nodejs-boilerplate .

    You should have a similar output:

    Creating a docker image
    Creating a docker image

    As you can see, the image has been successfully built and tagged. In docker, tagging is like version, and you use tagging to keep track of images when they are being deployed from one environment to another.

    Running the Docker Image (Locally)

    As we have successfully built our first docker image, we can display a list of images that we have built using the following command:

    docker images
    Docker images
    Docker images

    To generalize the run command for docker:

    docker run -p <external port>:<internal port> {image-id}

    Now, run the following command to execute our newly built docker image. Please keep in mind that, in your case, the Image ID will be different. By default, all docker containers do not permit any incoming connections, to fix that we use -p, which publishes all exposed ports to the interfaces.

    docker run -p 8080:3000 2f356f3dfec9

    You should have the following output, which states that you have successfully executed a docker container image that you have built on your computer:

    Successful output
    Successful output

    Now, let’s test it out, open your favorite browser and go to http://localhost:8080/ — you should have a similar screen:

    localhost8080
    localhost8080

    Monitoring a running Docker Container

    Let’s monitor our running docker container. To do that, simply type the following command in your terminal:

    docker container ls
    docker container ls
    docker container ls

    Stopping a Docker Container

    To stop a docker container, you can use the following command:

    docker stop {container-id}

    High-Level Overview of Amazon Architecture for Dockerization

    High Level Overview of Amazon Architecture for Dockerization
    High-Level Overview of Amazon Architecture for Dockerization

    Amazon Cloud is truly brilliant. I do agree, it does take a bit of cringing to get used to it, but once you get the hang of it, it can do marvels for you. In a nutshell, Amazon ECS (Elastic Container Service) is a service by Amazon that makes it easy for docker containers to be managed. The operations include start, stop, and manage its health. All docker containers are hosted on a cluster and that cluster can consist of more than one EC2 Instances. This makes it highly scalable (based on demand) and very fast.

    As we have seen locally, the docker files, in this case, create an image, that is spun into containers. The containers are then published into an ECR (Elastic Container Registry) which is a repository for storing these container images. Once you have the image on AWS, a task definition is created. A task definition is a set of instructions in JSON format for AWS to configure the container images to use, the environment variables to initialize, and the port mapping for networking. The task definition associated itself with a cluster that is created within the AWS ECS control panel. A cluster is the amount of RAM or CPU that is going to be consumed by the container. The scheduler that maintains the number of consistent instances defined by a task definition to keep it running in case of a failure is a service.

    Uploading your Docker Container Image to AWS

    Login to your AWS Console and type in ECR and then click on it.

    Read More:  Create simple POS with React.js, Node.js, and MongoDB #10: CRUD Supplier
    AWS Console
    AWS Console

    Click on Create Repository

    Create Repository
    Create Repository

    Give your repository a name

    Giving a repository a name
    Giving a repository a name

    You should now have the repository in the management panel:

    Repository in the management panel
    Repository in the management panel

    Note: At this point, you should have your AWS CLI Configured, before moving forward.

    Go to your terminal, and authenticate a user with ECR. To do that, use the following command:

    aws ecr get-login --no-include-email --region us-east-1

    You should now get a key with the complete command. Just copy and paste it again to successfully authenticate into AWS ECR.

    Secret Key
    Secret Key
    docker login -u AWS -p YOURSECRETKEY

    You will now see a login successful message.

    Now, we need to tag our image with reference to the image repository we created on ECR:

    docker tag <localimagename>:<tag> <onlineimageuri>:<tag>
    
    docker tag nodejs-boilerplate:latest 981984658744.dkr.ecr.us-east-1.amazonaws.com/nodejs-boilerplate:latest

    Then, push the image on AWS with the following command:

    docker push 981984658744.dkr.ecr.us-east-1.amazonaws.com/nodejs-boilerplate:latest

    You should have a similar output:

    Pushing the image on AWS
    Pushing the image on AWS

    If you check online in the AWS ECR Console, you should have your image up there.

    nodejs boilerplate
    nodejs boilerplate

    Now, go to ECS, in the Amazon Console:

    ECS in the Amazon Console
    ECS in the Amazon Console

    Then, go to Clusters and Create a New Cluster.

    Clusters
    Clusters

    We will be using an EC2 Linux + Networking cluster, which includes the networking component.

    Creating clusters
    Creating clusters

    For this configuration, we will be using a t2.micro and give your cluster a name.

    Configuring clusters
    Configuring clusters

    You should have a similar screen as below. Next click on view cluster.

    Launch status
    Launch status

    We also need to create a Task Definition, so click on Task Definition, and then — on Create new Task Definition.

    Task definitions
    Task definitions

    For this, we will be selecting an EC2 Compatibility

    Creating a new task definition
    Creating a new task definition

    Give your task a name. Scroll down, and click on Add Container.

    Configure task and container definitions
    Configure task and container definitions
    Container definitions
    Container definitions

    You would now require the URI from the Repository from ECR, make sure you copy it with the tag which is the latest Port mapping. It’s important to tell AWS which ports to export. In this case, we are redirecting all traffic from 80 to port 3000. The port 3000 is of the internal application running inside the container.

    Add container
    Add container

    Scroll down and configure the Environment variables. Set them to Production and then click Create.

    Environment
    Environment

    Once the task has been created, we need to create a service for it, therefore click on Actions and select Create Service

    Task definitions successfully created
    Task definitions successfully created

    The launch type is EC2 and the number of tasks is 1.

    Configure service
    Configure service

    Move forward and create the service. You should have the following success screen:

    Launch status 2
    Launch status 2

    Click on View Service and then on the Cluster

    myboilerplateservice
    myboilerplateservice

    Next, go to the EC2 instances tab and click on the Container Instance.

    You should finally have the URL that is public to view your running instance.

    Container instance
    Container instance

    Give yourself a pat if you are now able to see the following screen upon opening the Public DNS:

    Opening the Public DNS
    Opening the Public DNS

    Some Key Thoughts

    This might seem a bit hectic at the start, but once you make sense of things, I am sure you will have a better hold of the way things are working. This setup is very much preferred for critical tasks that one needs to be dependent in your application. Rather than having a single big application, your application can be broken down into smaller applications that work independently of each other like microservices.

    Reference

    https://www.statista.com/statistics/617136/digital-population-worldwide/
    https://docs.docker.com/engine/reference/builder/#run
    https://docs.docker.com/engine/reference/builder/#expose
    https://docs.aws.amazon.com/index.html?nc2=h_ql_doc_do
    https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html
    https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-basics.html
    https://www.statista.com/statistics/617136/digital-population-worldwide/

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Muhammad Bilal

      Related Posts

      An Introduction to Clustering in Node.js

      March 26, 2024

      Server-Side Rendering with Vue.js and Nuxt.js

      February 26, 2024

      Mastering N-API and Native Modules in Node.js

      February 13, 2024
      Leave A Reply Cancel Reply

      You must be logged in to post a comment.

      Stay In Touch
      • Facebook
      • Twitter
      • Pinterest
      • Instagram
      • YouTube
      • Vimeo
      Don't Miss
      CSS April 21, 2023

      CSS Grid

      Cascading Style Sheets Grid Layout, or CSS Grid for short, is a fantastic layout framework made especially for creating flat web designs. It’s a revolutionary step forward in the world of CSS, providing a flexible and user-friendly method for arranging elements on a web page in rows and columns with infinite customization options.

      How to Hire a Freelance Web Developer: Things to Look For and Avoid

      February 19, 2019

      Build Real-World React Native App #7: Send Feedback with Formik, Yup, Firebase Cloud Function and Sendgrid

      December 15, 2020

      Leveraging Data Analytics for Informed Business Decisions

      December 17, 2024

      Categories

      • AI & Automation
      • Angular
      • ASP.NET
      • AWS
      • B2B Leads
      • Beginners
      • Blogs
      • Business Growth
      • Case Studies
      • Comics
      • Consultation
      • Content & Leadership
      • CSS
      • Development
      • Django
      • E-commerce & Retail
      • Entrepreneurs
      • Entrepreneurship
      • Events
      • Express.js
      • Facebook Ads
      • Finance & Fintech
      • Flask
      • Flutter
      • Franchising
      • Funnel Strategy
      • Git
      • GraphQL
      • Home Services Marketing
      • Influencer & Community
      • Interview
      • Java
      • Java Spring
      • JavaScript
      • Job
      • Laravel
      • Lead Generation
      • Legal & Compliance
      • LinkedIn
      • Machine Learning
      • Marketing Trends
      • Medical Marketing
      • MSP Lead Generation
      • MSP Marketing
      • NestJS
      • Next.js
      • Node.js
      • Node.js Lessons
      • Paid Advertising
      • PHP
      • Podcasts
      • POS Tutorial
      • Programming
      • Programming
      • Python
      • React
      • React Lessons
      • React Native
      • React Native Lessons
      • Recruitment
      • Remote Job
      • SaaS & Tech
      • SEO & Analytics
      • Soshace
      • Startups
      • Swarm Intelligence
      • Tips
      • Trends
      • Vue
      • Wiki
      • WordPress
      Top Posts

      Node.js Lesson 14: Asynchronous Development

      JavaScript January 6, 2021

      Contentful+Gatsby = Smarter content management

      JavaScript September 2, 2019

      Adding backend to CodePen snippet using Python/Django | Question-Answering Application

      Python April 28, 2020

      Introduction to Vue.js Event Handling

      JavaScript January 20, 2020

      Subscribe to Updates

      Get The Latest News, Updates, And Amazing Offers

      About Us
      About Us

      Soshace Digital delivers comprehensive web design and development solutions tailored to your business objectives. Your website will be meticulously designed and developed by our team of seasoned professionals, who combine creative expertise with technical excellence to transform your vision into a high-impact, user-centric digital experience that elevates your brand and drives measurable results.

      7901 4th St N, Suite 28690
      Saint Petersburg, FL 33702-4305
      Phone: 1(877)SOSHACE

      Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
      Our Picks
      JavaScript

      Writing end-to-end tests for Nuxt apps using jsdom and AVA

      Programming

      23. Уроки Node.js. Домены, “асинхронный try..catch”. Часть 1.

      Consultation

      Consulting Project Prepare for a new job

      Most Popular

      Strategic Seasonal Campaign Concepts for Online and Retail Markets

      E-commerce & Retail

      Technical Writing: Practical & Theoretical Advice

      Beginners

      22. Чат Через Long-Polling. Чтение POST. Pt.2.

      Programming
      © 2025 Soshace Digital.
      • Home
      • About
      • Services
      • Contact Us
      • Privacy Policy
      • Terms & Conditions

      Type above and press Enter to search. Press Esc to cancel.