๐ŸŽ‰ Building and Testing a Flask App with Docker: A Step-by-Step Guide ๐Ÿš€

๐ŸŽ‰ Building and Testing a Flask App with Docker: A Step-by-Step Guide ๐Ÿš€

ยท

2 min read

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
  1. 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! ๐Ÿš€

Here are my POC Result

Did you find this article valuable?

Support Divya_satpute's_blog by becoming a sponsor. Any amount is appreciated!

ย