This is a simple Flask-based web application that performs basic arithmetic operations (addition, subtraction, multiplication, division). The application is containerized using Docker and deployed on an AWS EC2 instance.
- Web-based calculator UI (HTML, JavaScript, and Flask backend)
- Dockerized for easy deployment
- Hosted on an AWS EC2 instance
- Publicly available on Docker Hub
Before you begin, ensure you have the following:
- An AWS EC2 instance (Amazon Linux 2 or Ubuntu)
- Docker installed on the EC2 instance
- A Docker Hub account
- Git installed on the EC2 instance
- Go to the AWS Console, navigate to EC2, and launch an instance.
- Select Amazon Linux 2 or Ubuntu as your OS.
- Choose an instance type (t2.micro for free-tier eligibility).
- Configure security group:
- Allow port 22 (SSH) for remote access.
- Allow port 5000 (Flask app) for HTTP access.
- Launch the instance and connect via SSH:
ssh -i your-key.pem ec2-user@your-ec2-ip
sudo yum update -y
sudo yum install docker -y
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker ec2-userThen, reconnect to apply changes.
sudo apt update -y
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker ubuntuIf your EC2 instance does not have Python installed:
sudo yum install python3 -y # Amazon Linux
sudo apt install python3 -y # UbuntuThen, install Flask:
pip3 install flaskOn your EC2 instance, clone the repository:
git clone https://github.com/your-github-username/FlaskCalculator.git
cd FlaskCalculatorInside your FlaskCalculator directory, create a file named Dockerfile:
nano DockerfilePaste the following content:
# Use an official Python runtime as the base image
FROM python:3.9-slim
# Set the working directory inside the container
WORKDIR /app
# Copy application files to the container
COPY . /app
# Install dependencies
RUN pip install --no-cache-dir flask
# Expose the application port
EXPOSE 5000
# Command to run the application
CMD ["python", "app.py"]Save and exit (CTRL + X, then Y, then Enter).
docker build -t flask-calculator .docker run -d -p 5000:5000 flask-calculatordocker ps- Open a browser and visit:
http://your-ec2-ip:5000 - If it's not accessible, update your EC2 security group:
- Allow port 5000 for 0.0.0.0/0 (for testing, restrict later).
docker loginEnter your Docker Hub username and password.
Replace your-docker-username with your actual Docker Hub username.
docker tag flask-calculator your-docker-username/flask-calculatordocker push your-docker-username/flask-calculatorYour image is now publicly available on Docker Hub!
To run the container on another machine or EC2 instance:
docker pull your-docker-username/flask-calculator
docker run -d -p 5000:5000 your-docker-username/flask-calculatorNow, your app is running from Docker Hub! 🚀