# From Docker Demos to EC2 Deployments

## Introduction

Hello there! 👋 The past week marked **Week 6** of my DevOps journey, and it was the beginning of something more hands-on and real-world focused. After completing most of the fundamental concepts, I was about to start learning Docker and Kubernetes, but a YouTube video changed the course a bit.

It is recommended learning cloud computing first, then explore containerization and deployment tools *in the context of the cloud.* That clicked for me. So, this week, I started exploring containerization concepts, got familiar with microservices architecture, and kicked off with AWS Fundamentals. Here's how the week unfolded:

---

## Understanding Containerization and Docker

I began with a simple question: **"What is a container?"**

**Containers** are lightweight, portable environments that package an application and all its dependencies together.

### Advantages of Containers:

* Consistency across development, testing, and production.
    
* Portability across platforms (Docker, Podman).
    
* Scalability for service expansion and contraction.
    
* Efficiency compared to VMs.
    

The most widely used tool for containerization, as we all know, is **Docker**. So, I learned about Docker, a platform for developing, shipping, and running applications in containers.  
I understood the flow for creating a Docker container -

* Write a Dockerfile with commands like `FROM`, `RUN`, `CMD`, etc.
    
* Build a Docker Image from the Dockerfile.
    
* Use that image to run a Docker Container.
    

### Docker Architecture

Docker follows a Client-Server model:

* Docker Client → CLI or GUI for user interaction
    
* Docker Daemon → Manages containers in the background
    
* Docker Registry → Stores Docker images (e.g., DockerHub)
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1744525509926/877e8433-0af0-4f63-8b2d-e2a2e2b10631.png align="center")

### Scenario: Nginx Web Server in Docker

I noted a simple scenario for reference: running an Nginx Web Server in Docker. It involves the following steps -

1. Install **Docker** on your system.
    
2. Pull the Nginx image\*\* from DockerHub
    
    ```bash
    docker pull nginx
    docker run -d -p 8080:80 --name my-nginx nginx
    ```
    
    Visit `http://localhost:8080` to see it in action.
    
3. Container Management
    
    ```bash
    docker ps
    docker stop my-nginx
    docker rm my-nginx
    ```
    

To get a hold of how Docker containers are created and run inside a VM, I set up Docker inside a VM:

1. Create a VM using Vagrant and configure it using Vagrantfile.
    
2. Run the VM using vagrant up, log in to it using SSH and switch to the root user.
    
3. Basic Commands
    
    ```bash
    systemctl status docker
    docker run hello-world
    
    docker images
    docker ps
    docker ps -a
    ```
    
4. Run a container
    
5. Building an image
    
    ```bash
    mkdir images
    cd images/
    vim Dockerfile
    ```
    
    ```docker
    FROM ubuntu:latest AS BUILD_IMAGE
    RUN apt update && apt install wget unzip -y
    RUN wget https://www.tooplate.com/zip-templates/2128_tween_agency.zip
    RUN unzip 2128_tween_agency.zip && cd 2128_tween_agency && tar -czf tween.tgz * && mv tween.tgz /root/tween.tgz
    
    FROM ubuntu:latest
    LABEL "project"="Marketing"
    ENV DEBIAN_FRONTEND=noninteractive
    
    RUN apt update && apt install apache2 git wget -y
    COPY --from=BUILD_IMAGE /root/tween.tgz /var/www/html/
    RUN cd /var/www/html/ && tar xzf tween.tgz
    CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
    VOLUME /var/log/apache2
    WORKDIR /var/www/html/
    EXPOSE 80
    ```
    
    ```bash
    docker build -t tesimg .
    docker images
    # Run container from the Image
    docker run -P -d tesimg
    docker ps
    
    ip addr show
    docker ps
    ```
    
6. Go to the browser and enter IP\_Addr:HostPort
    
7. Cleaning up containers and images. This sample Dockerfile I pulled from the internet to test the creation of a Docker container.
    

## Learning Microservices Architecture

I also learned about **Microservices** - what Microservices architecture is, how it is different from the previously used Monolithic architecture. The ideology of **Microservices** is breaking down a monolith into several smaller, self-contained services, each responsible for a specific business functionality. This introduces isolation, loose coupling and flexibility in choosing technology.

### Communication Methods:

* **Synchronous** (APIs)
    
* **Asynchronous** (Message brokers like RabbitMQ)
    
* **Service Mesh**
    

I also explored:

* **Monorepo vs Polyrepo** code strategies
    

Although I stayed on a theoretical level for now, I plan to go deeper with projects soon.

## Getting Started with AWS

Since cloud was the next big milestone, I turned to AWS Fundamentals. Thankfully, I had some theoretical exposure from a course I took last semester, which helped me understand things quickly.

### Important AWS Services for DevOps:

➡️ Compute: EC2, Lambda, Beanstalk

➡️ Storage: S3, EBS

➡️ Identity: IAM, KMS

➡️ Monitoring: CloudWatch, CloudTrail, X-Ray

➡️ Networking: VPC, ELB, Route53

➡️ Containers: ECS, EKS, ECR

➡️ CI/CD: CodeCommit, CodeBuild, CodeDeploy, CodePipeline

## Deep Dive into EC2 Instances

I created multiple EC2 instances and:

* Played with **Security Groups**, **Key Pairs**, and **Elastic IPs**
    
* Hosted a **static HTML page** on an Ubuntu server using Apache2
    
    ![](https://docs.aws.amazon.com/images/AWSEC2/latest/UserGuide/images/tutorial-test-instance.png align="left")
    

### AWS CLI:

Next, I learned about AWS CLI, which lets users interact with AWS services from the terminal. It also helps in automation, scripting, and managing resources via the terminal.

* Installed CLI on my machine
    
* Created an IAM user and configured it with Access Keys
    
* Practiced launching instances, creating key pairs, and security groups via CLI
    

## EBS Volumes & Snapshots

Each EC2 instance comes with a block storage volume (EBS). I learned:

* Types of EBS volumes
    
* Creating, attaching, and configuring them
    
* Creating partitions, mounting and unmounting them persistently
    
* Snapshots for backup and restore
    

## Load Balancing with ELB

I created multiple EC2 instances using:

* AMIs and Launch Templates
    
* Hosted a basic HTML page on each
    
* Created **Target Groups** and an **Application Load Balancer (ALB)**
    
* Configured listeners and verified load distribution
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1744525560502/fb3fb983-4599-4372-8303-8054c4198ce1.png align="center")

## Monitoring with CloudWatch & SNS Alarms

I used **CloudWatch** to monitor CPU usage on an EC2 instance and:

* Created **SNS Topic** and Subscription
    
* Configured **Alarms** to notify me via **email** or **SMS**
    

Faced some issues with email alerts, but SMS notifications worked as expected.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1744525595864/0a2afb66-820b-4bd0-85ba-dec215128205.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1744526794464/5390e2bc-47f3-438d-b451-00215566f7d1.jpeg align="center")

## Resources I Used

1. [Docker Documentation](https://docs.docker.com/get-started/docker-overview/)
    
2. [Microservices | Techworld with Nana](https://youtu.be/rv4LlmLmVWk?si=yIy-ufm-ksWSb5tv)
    
3. [AWS | Cloud Computing](https://aws.amazon.com/what-is-cloud-computing/)
    
4. [AWS CLI | Command References](https://docs.aws.amazon.com/cli/latest/reference/)
    

## Challenges I Faced

**1️⃣ Microservices Mini Project Not Working**

* After learning the basics of microservices, I tried building a small demo project using a sample `docker-compose.yml` file I found online. My goal was to spin up a few lightweight containers as independent services inside a VM. However, the setup consistently failed to build and run. Even after debugging the Dockerfile, checking for dependency issues, and validating port configurations, I couldn’t get the containers running inside the VM. I eventually paused the project and plan to revisit it later with a more hands-on guide.
    

**2️⃣ Security Group Misconfiguration for SSH**

* While working with EC2 instances, I created a new instance and configured the inbound rules via the security group to allow SSH access. However, every time I tried to log in using my key pair, I received a "Permission denied" error. I temporarily opened the rule to allow SSH from all IPs (`0.0.0.0/0`), and it worked. But that’s not a secure long-term solution. I terminated the instance, recreated it with the exact same rule settings and, surprisingly, this time, SSH worked perfectly. Still unsure what caused the initial misbehavior.
    

**3️⃣ CloudWatch Alarm Emails Not Delivering**

* I wanted to test CPU utilization monitoring and email alerts using AWS CloudWatch. After configuring everything, the alarm triggered correctly, but I wasn’t receiving emails. The SNS subscription for my email kept showing as "Pending Confirmation" despite confirming multiple times. After researching, I suspected my email address might be on AWS SES's suppression list. As a workaround, I created a new subscription using the **SMS protocol** and tested it using my mobile number - which worked flawlessly. Still need to confirm what happened to my email with AWS support, or try a different email next time.
    

## What's Next?

Before exams hit, I plan to:

* Learn **EFS**, **Auto Scaling Groups**, and **S3**
    
* **Revise** previously covered concepts
    

## Let’s Connect!

🔗 [My LinkedIn](https://www.linkedin.com/in/akshansh-singh-3b6718250/)

🔗 [My GitHub](https://github.com/akshansh029)

If you have any helpful resources or better ways to solve the challenges I faced, or just want to chat about DevOps, drop a comment!

**Have a wonderful day!**
