Skip to content

sankar-nath/Two-Tier-Web-Application-running-as-a-docker-container

 
 

Repository files navigation

This repository was cloned from my professor's repo to complete the first assignment for CLO835 In this Assignment we deployed containerized application. The web application takes in employee details and stores it in a database. Both the app and the database are being run as containers running on an EC2 instance.

Instructions

  1. Go to the terraformCode folder and run tf to create the EC2 instance, two ECR repositories and the security group.
  2. From the repository, run the ecr.yml file to create docker images which will get pushed to the ECR repositories
  3. Log in to EC2 instance, pull the docker images, run the sql container and then the webapp container.
  4. Use the public IP of the ec2 instance to access the web app.

Install the required MySQL package

sudo apt-get update -y sudo apt-get install mysql-client -y

Running application locally

pip3 install -r requirements.txt sudo python3 app.py

Building and running 2 tier web application locally

Building mysql docker image

docker build -t my_db -f Dockerfile_mysql .

Building application docker image

docker build -t my_app -f Dockerfile .

Running mysql

docker run -d -e MYSQL_ROOT_PASSWORD=pw my_db

Get the IP of the database and export it as DBHOST variable

docker inspect <container_id>

Example when running DB runs as a docker container and app is running locally

export DBHOST=127.0.0.1
export DBPORT=3307

Example when running DB runs as a docker container and app is running locally

export DBHOST=172.17.0.2
export DBPORT=3306
export DBUSER=root
export DATABASE=employees
export DBPWD=pw
export APP_COLOR=blue

Run the application, make sure it is visible in the browser

docker run -p 8080:8080 -e DBHOST=$DBHOST -e DBPORT=$DBPORT -e DBUSER=$DBUSER -e DBPWD=$DBPWD my_app

About

forking this repo to complete my CLO835 assignment 1

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 40.9%
  • HTML 35.4%
  • HCL 20.7%
  • Dockerfile 3.0%