๐ 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!
๐ Prerequisites
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 :
https://github.com/divyasatpute/Docker-material/tree/master/FLASK
git clone https://github.com/divyasatpute/Docker-material.git
Change directory
cd Docker
Go to directory where is your Dockerfile
cd FLASK
๐ณ Create a Dockerfile
# 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 divyasatpute/sanity-test
Now โ Testing Your Flask App
๐ Access Your Flask Application
Copy public IP of your Instance and paste on tab
127.152.55.44:8080
๐ 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! ๐