DevOps Project-1 : Deploying a web application on an EC2 instance

Deploying a web application on an EC2 instance is a great way to get started with DevOps. In this blog, I will walk you through the step-by-step process of deploying a simple React and Node application on an EC2 instance using Docker.

Step 1: Create an EC2 instance on AWS First, log in to your AWS account and navigate to the EC2 dashboard. Click on "Launch Instance" and choose an Amazon Machine Image (AMI) that suits your needs. Select the instance type, configure the instance details, add storage, and configure the security group to allow inbound traffic on port 22 (SSH) and port 80 (HTTP).

Step 2: Connect to the EC2 instance with SSH Once the EC2 instance is up and running, you can connect to it using SSH. Open your terminal and use the following command to connect to the instance:

ssh -i your-key.pem ec2-user@your-instance-ip

Step 3: Install Docker on the remote EC2 instance After connecting to the EC2 instance, you need to install Docker. Run the following commands to install Docker:

sudo yum update -y

sudo amazon-linux-extras install docker

sudo service docker start

sudo usermod -a -G docker ec2-user

exit

Then reconnect to the EC2 instance using SSH to apply the usermod changes.

Step 4: Push the application image to Docker Hub For this project, I have used a simple React and Node application from Nana Janashia and built a Docker image for it. After building the image, I pushed it to a private repository on Docker Hub.

Step 5: Run the Docker container from the private repo Back on the EC2 instance, pull the Docker image from the private repository using the following command:

docker pull your-private-repo/your-image:tag

Then run the container with the following command:

docker run -d -p 80:3000 your-private-repo/your-image:tag

Step 6: Configure the EC2 firewall to access the app externally To access the web application from a web browser, you need to configure the security group associated with the EC2 instance. Go back to the EC2 dashboard, select your instance, and click on "Security groups." Edit the inbound rules to allow traffic on port 80 from anywhere (0.0.0.0/0).

And that's it! Your web application should now be accessible from a web browser using the public IP address of your EC2 instance.

I hope this beginner-friendly DevOps project has been helpful in understanding the basics of deploying a web application on an EC2 instance using Docker. Happy coding!