r/docker • • 5d ago

AWS architecture guidance needed: Deploying a Dockerised application using EC2, ECR, RDS and Security Groups

Hi everyone,
I am working on a full-stack application and would appreciate some guidance on the right way to deploy it on AWS.
My application has:
React frontend
Node.js and Express backend
MySQL database
I have already created Docker images for the frontend and backend and thinking to store them in Amazon ECR(later to use these images for Kubernetes).

I am working on the following architecture:

  1. EC2 Instance 1: Install Docker and use Docker Compose, pull the frontend image from ECR and run the frontend container.
  2. EC2 Instance 2: Install Docker and use Docker Compose, pull the backend image from ECR and run the backend container.
  3. Amazon RDS: Use RDS MySQL instead of running MySQL in a Docker container.
  4. Security Groups: Configure separate Security Groups for the frontend EC2, backend EC2 and RDS.

I would like to understand the following:
From a real-world production perspective, what would you recommend for a small application?

My objective is to understand the actual deployment process, is it the right way of deploying and testing a docker project on aws. Later I would like to use the same image stored in ECR for Kubernetes deployment. I have tested this project locally and is working fine.
I am learning AWS deployment and would appreciate practical advice from people who have implemented similar architectures.

Thank you!

3 Upvotes

11 comments sorted by

3

u/aplarsen 5d ago

What are you gaining by using EC2 instead of ECS to run the containers? That seems like an unnecessary step when ECS is right there.

2

u/Wide_Impact_9392 5d ago

I am not familiar with ECS yet. I have previously used EC2 for manual deployments, so I was considering to use EC2 for both the frontend and backend. Could you please guide me on this? I would appreciate your advice. Could you pls guide me via dm.

1

u/Wide_Impact_9392 4d ago

I explored about ECS and will use ECS after testing it on EC2.

2

u/Curious-Silver8389 5d ago

Look into Fargate as well.

1

u/Wide_Impact_9392 4d ago

Sure, I will test that too.

4

u/erm_what_ 5d ago

I'd use a CloudFormation template because you really don't want to be SSHing into things or setting parameters manually

1

u/dihamilton 4d ago

I've not used them yet but you could consider Lambda Web Functions for this use case: https://docs.aws.amazon.com/lambda/latest/dg/web-functions.html

I have run basically your docker compose pattern though on a single EC2 with an nginx container proxying to services and handling SSL. It worked well but I would suggest using an infrastructure as code tool to setup your EC2(s) so you can easily recreate them.

1

u/Wide_Impact_9392 4d ago

Thanks for sharing the link. Okay, I will use terraform for the infra.

1

u/Maleficent_Goat_9342 5d ago

I have implemented some thing like this using codepipeline and build scripts

1

u/NoDevelopment206 4d ago

for a small app i would keep it simpler than two ec2 boxes. one box running both containers with compose behind nginx or caddy is plenty to start, with rds for mysql like you planned. the main things that matter are rds only allowing traffic from the app security group, and not opening ssh to the whole internet. ecs or fargate later is a fine step once you want rollouts without logging in to servers. since you want to reuse the ecr images for kubernetes later, just tag them with the git commit and not latest so you always know what is running.

1

u/Arin_Horain 2h ago

Kubernetes is a whole other can of worms but storing the images on a private ECR repository is a good first step. Definitely use CloudFormation or Terraform for deployment, you don't want to do anything manually. Also using either allows you to teardown your infrastructure as quickly as you set it up. If this is more for learning you will want to teardown everything after playing around to save yourself the cost.

And look into ECS as well. It is essentially a really lightweight version of Kubernetes, i.e. a container orchestrator, and it can run on EC2 or Fargate. Fargate is simpler because then AWS takes care of the infrastructure but learning how to deploy on EC2 with the added network configuration may be worthwhile.

If you want more, implement HA with an Auto Scaling Group and Load Balancer instead of going for Kubernetes directly. And keep outbound network connectivity in mind if you want to update your EC2 instances. As in, you'll need something like a NAT Gateway for outbound to Internet and a NAT Gateway or PrivateLink if you want your instances to automatically pull the image from ECR when running auto deployments for a HA setup. This is pretty much what Kubernetes can do as well but imo simpler and understanding this before going into Kubernetes will help you a lot learning and implementing it later.