Deploying Full Stack Applications On Aws Ec2 With Docker A

Leo Migdal
-
deploying full stack applications on aws ec2 with docker a

In the ever-evolving world of web development, one of the most empowering things you can do is take your application from local development all the way to the cloud — and that’s exactly what... Over the past few days, I built and deployed a full-stack application consisting of a React frontend and an Express.js backend, fully containerized and hosted on AWS ECS using Fargate. Here’s a look behind the scenes of how I transformed lines of code into a cloud-native, production-grade deployment. The architecture was simple but effective: a React frontend communicating with an Express backend. I began by developing both apps locally and testing them with Docker to ensure container compatibility. Each app was placed in its own Docker container with production-ready configurations.

Created a new cluster using Fargate launch type. No EC2 instances needed! Welcome to my Full Stack Application Deployment With Docker project! 🚀 This project demonstrates the power of Docker and Docker Compose in deploying a full stack application seamlessly on AWS EC2. Whether you're a seasoned developer or just getting started with containerization, this project provides an excellent opportunity to dive into deploying complex applications with ease.

Building and deploying full stack applications can be a daunting task, especially when it comes to managing dependencies, environments, and scaling. With Docker, I simplify this process by encapsulating each component of the application into containers, ensuring consistency across development, testing, and production environments. If any environment variables are required, create a .env file in the root directory of the project and define the variables there. Once the containers are up and running, access the application in your web browser using the public IP address of your AWS EC2 instance. Replace localhost with the public IP address. EC2 stands for Elastic Cloud Computing and is a service that AWS offers for running applications, hosting websites, processing data, and performing other computing operations.

We will push our MERN project frontend and backend into two different repositories on GitHub from our local machine. After that, using GitHub actions, we will build a Docker image for both repositories separately. These images will be pushed to DockerHub and saved in two different repositories on DockerHub. On AWS, we will configure a self-hosted runner for both the front end and back end. When our image is pushed to DockerHub, then our AWS self-hosted runner will pull the image from DockerHub. After this, our application will run on EC2.

First, we will deploy the backend, and then, in a similar way, we will deploy the frontend. Hurray! Now you have hosted the MERN stack application on EC2. Here I have my "Book Store," an application developed using the MERN stack. To deploy any MERN stack application, the process is similar. Login to DockerHub and create two public repositories, one for the frontend and the other for the backend.

Also, note the username and repository name that we will need when we write the CICD workflow for our frontend and backend applications. Remember, we have to store our DockerHub username and password in GitHub secrets when we create a repository for our project on GitHub. In today's fast-paced world of software development, the ability to quickly package, deploy, and scale applications on public cloud infrastructure has become more essential than ever. Containerization has truly revolutionized these processes, with Docker standing out as a catalyst in the advancement of this movement. Docker containers can provide consistent runtime environments for your applications, allowing developers to build, deploy, and iterate with unprecedented efficiency. Containers make a lot of sense in the public cloud.

The cloud offers a powerful and versatile platform for provisioning infrastructure, so enterprises no longer have to plan their infrastructure requirements well ahead of their current needs. Instead, they can quickly scale their resources up and down as necessary. Moreover, big cloud providers offer various services that can easily integrate with containerized applications, making it even easier for organizations to reduce their operational burdens. There are many cloud providers out there, but Amazon Web Services (AWS) undoubtedly stands out as the current market leader. Services such as Amazon Elastic Compute Cloud (EC2), Amazon Relational Database Service (RDS), and Amazon Elastic Container Service (ECS) can drastically simplify the orchestration, scaling, and management of Docker containers, making it easier for... This article will guide you through several possible methods of deploying your containerized applications on AWS.

You'll start by preparing the Docker images for your application containers and setting up the necessary infrastructure (provisioning a relational database and configuring networking settings). You'll then explore a valid but laborious method for deployment based on EC2 instances and auto-scaling groups. This will give you the fundamentals needed for understanding the more advanced deployment method presented in this tutorial, which shows you how to deploy your containers on a serverless platform using AWS ECS. By the end of this tutorial, you'll have a much deeper understanding of how serverless environments like AWS ECS operate and will be well-equipped to deploy your containerized applications on cloud infrastructure. The objective of this project was to deploy a complete and functional full-stack web application, composed of a frontend (Nginx/HTML), a backend (Flask/Python), and a database (MySQL). The entire architecture was containerized using Docker and deployed on an AWS infrastructure.

The AWS architecture was configured to route traffic securely and in a controlled manner to the application. A CloudFront distribution was deployed to receive all public user traffic. This distribution is configured to forward requests to a single EC2 instance. The EC2 instance serves as the host where the Docker environment runs. To control access, a Security Group was configured to act as a firewall, allowing incoming TCP traffic only on ports 8090 (frontend) and 5001 (backend API). The remaining ports, including the database port, are not accessible from the internet.

The application was broken down into three independent but interconnected services, each with its own container, orchestrated within the EC2 instance. You’ve built and tested your Docker Compose app locally — now it’s time to go live! In this guide, I’ll walk you through deploying a multi-container application using Docker Compose on an AWS EC2 instance. This setup is perfect for staging, testing, or lightweight production environments. ✅ Full control over environment✅ Cost-effective and scalable✅ Great for Dockerized apps and DevOps testing✅ Useful for MVPs, personal projects, and client demos Reboot or log out and log back in to apply group permissions.

If you don’t have a Compose setup yet, here’s a working example of a Flask + PostgreSQL stack.

People Also Search

In The Ever-evolving World Of Web Development, One Of The

In the ever-evolving world of web development, one of the most empowering things you can do is take your application from local development all the way to the cloud — and that’s exactly what... Over the past few days, I built and deployed a full-stack application consisting of a React frontend and an Express.js backend, fully containerized and hosted on AWS ECS using Fargate. Here’s a look behind ...

Created A New Cluster Using Fargate Launch Type. No EC2

Created a new cluster using Fargate launch type. No EC2 instances needed! Welcome to my Full Stack Application Deployment With Docker project! 🚀 This project demonstrates the power of Docker and Docker Compose in deploying a full stack application seamlessly on AWS EC2. Whether you're a seasoned developer or just getting started with containerization, this project provides an excellent opportunit...

Building And Deploying Full Stack Applications Can Be A Daunting

Building and deploying full stack applications can be a daunting task, especially when it comes to managing dependencies, environments, and scaling. With Docker, I simplify this process by encapsulating each component of the application into containers, ensuring consistency across development, testing, and production environments. If any environment variables are required, create a .env file in th...

We Will Push Our MERN Project Frontend And Backend Into

We will push our MERN project frontend and backend into two different repositories on GitHub from our local machine. After that, using GitHub actions, we will build a Docker image for both repositories separately. These images will be pushed to DockerHub and saved in two different repositories on DockerHub. On AWS, we will configure a self-hosted runner for both the front end and back end. When ou...

First, We Will Deploy The Backend, And Then, In A

First, we will deploy the backend, and then, in a similar way, we will deploy the frontend. Hurray! Now you have hosted the MERN stack application on EC2. Here I have my "Book Store," an application developed using the MERN stack. To deploy any MERN stack application, the process is similar. Login to DockerHub and create two public repositories, one for the frontend and the other for the backend.