Building and Testing a Flask App with Docker: A Step-by-Step Guide ๐

Creating and testing a Flask application using Docker can streamline your development process, ensuring consistency across different environments. This guide will walk you through the steps to set up and test a Flask application using Docker. Let's get started!
Before we begin, make sure you have the following installed:
install Docker on your AWS machine
AWS EC2 Machine
๐ Step-by-Step Guide
1. ๐ Set Up Your Project Directory
clone my repo on Github :
git clone https://github.com/omkarthorbole15701/Docker-material.git
Change directory:
cd Docker-materials
Go to directory where is your Docker file.
cd FLASK
๐ณ Create a Docker file
# Use a specific version of Python with Alpine
FROM python:2.7-alpine3.10
# Set the working directory
WORKDIR /usr/src/app
# Install dependencies
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
# Copy the application files
COPY app.py ./
COPY templates/index.html ./templates/
# Expose the port the app runs on
EXPOSE 5000
# Define the command to run the application
CMD ["python", "app.py"]
๐ Build Your Docker image:
docker build -t divyasatpute/sanity-test .
Run your container
docker run -p 8080:5000 --name testcase omkarthhorbole15701/sanity-test

Now โ Testing Your Flask App
๐ Access Your Flask Application
Copy public IP of your Instance and paste on tab
Conclusion
By following these steps, you've successfully deployed your Flask application using Docker and exposed it to the internet with a public IP address. This setup is suitable for testing and development purposes. For production, consider additional steps for security, scalability, and performance optimization. Happy coding! ๐
Here are my POC Result


