Prerequisites:
Install Docker: Make sure Docker is installed on your system. You can download it from Docker's official site.
Install Python: Ensure you have Python installed (version 3.8+).
Install Git: If you need version control, install Git for cloning repositories or managing versions.
Steps: Step 1: Set Up Your Project Directory Open a terminal (or Git Bash). Create a directory for your Flask project and navigate into it: mkdir flask-docker-app cd flask-docker-app
Step 2: Create a Virtual Environment and Install Flask Set up a virtual environment to isolate your Python dependencies:
python3 -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate Install Flask:
pip install Flask
Freeze your installed dependencies into a requirements.txt file:
pip freeze > requirements.txt
Step 3: Create a Simple app.py Flask Application
Step 4: Create a Dockerfile
Step 5: Build the Docker Image docker build -t flask-docker-app .
Step 6: Run the Docker Container docker run -p 5050:5050 flask-docker-app
Step 7: Test Your Flask App
Open your web browser and go to http://localhost:5050