Deploying a Static Web Application with Docker on AWS

1. Objective

The objective of this project was to deploy a static web page (index.html), packaged in a Docker image, onto a secure and optimized AWS environment provisioned via Infrastructure as Code.

2. Infrastructure on AWS

An AWS CloudFormation template was used to automate the provisioning of a robust architecture, which consisted of:

  • A CloudFront Distribution acting as the global entry point, providing edge caching, SSL/TLS termination (HTTPS), and an additional layer of security.
  • An EC2 instance that serves as the host for the Docker environment where the application resides.
  • A Security Group configured to allow the EC2 instance to only accept traffic from the CloudFront distribution, isolating it from direct internet access.

3. Application Containerization

Starting with a custom index.html file, a Dockerfile was defined with the following key steps:

  • Base Image: The official nginx image was used as a base for its lightweight and efficient static content serving capabilities.
  • File Copying: The COPY instruction was configured to transfer the local index.html to Nginx’s default web directory inside the container (/usr/share/nginx/html).

4. Deployment and Execution

The deployment process on the EC2 instance was carried out in two phases:

  • Image Build: The Docker image was generated from the Dockerfile with the command: docker build -t simple-nginx .
  • Container Execution: A container was started from the created image, exposing the application internally: docker run -d -p 8090:80 --name server simple-nginx

This command mapped port 80 of the container (where Nginx listens) to port 8090 on the host EC2 instance.

5. Verification

The application’s successful deployment was verified by accessing the public URL provided by the CloudFront distribution from a web browser. CloudFront handles securely redirecting the request to the EC2 instance on port 8090.

Scroll al inicio