Skip to content

This project shows how to Dockerize a Flask app. 🐳 By containerizing, you get consistent deployment and easier management. It integrates AI services for handling different data types, demonstrating Docker's power and flexibility. πŸš€

Notifications You must be signed in to change notification settings

AnurupaK/Dockerizing_Flask_App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Dockerizing a Flask Application πŸš€

Welcome to the guide on Dockerizing a Flask application! This README provides a comprehensive guide on setting up, building, and running a Dockerized Flask app, along with some useful Docker commands.

πŸ“ Project Structure

Here is the directory structure of the Flask project:

Flask_App/
β”œβ”€β”€ AI_Service/
β”‚   β”œβ”€β”€ gemini_response_text.py
β”‚   └── gemini_response_image.py
β”œβ”€β”€ Backend/
β”‚   └── app.py
β”œβ”€β”€ Frontend/
β”‚   β”œβ”€β”€ static/
β”‚   β”‚   β”œβ”€β”€ Images/
β”‚   β”‚   β”‚   └── icon.jpg
β”‚   β”‚   β”œβ”€β”€ style.css
β”‚   β”‚   └── script.js
β”‚   └── templates/
β”‚       └── index.html
β”œβ”€β”€ uploads/
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ .env
└── requirements.txt
  • AI_Service/: Contains scripts for processing text and image responses.
  • Backend/: Includes the main Flask application file.
  • Frontend/: Holds static files (CSS, JavaScript, images) and HTML templates.
  • uploads/: Directory for storing uploaded files.
  • Dockerfile: Configuration file for building the Docker image.
  • .env: Environment variables.
  • requirements.txt: Python dependencies.

πŸ› οΈ Getting Started

1. Setting Up the Flask Project

Before Dockerizing, ensure your Flask application is set up correctly:

  1. Create a virtual environment (optional but recommended):

    python -m venv venv
  2. Install dependencies:

    pip install -r requirements.txt
  3. Run the Flask app locally to verify everything works:

    python Backend/app.py

2. Building the Docker Image

Build the Docker image for your Flask app using:

docker build -t flask-app .

3. Running the Docker Container

Run the Docker container and map the local uploads directory to the container’s uploads directory:

docker run -p 3000:3000 -v "$(pwd)/uploads:/app/uploads" flask-app
  • -p 3000:3000: Maps port 3000 on your local machine to port 3000 in the container.
  • -v "$(pwd)/uploads:/app/uploads": Shares the uploads directory between your host and the container.

4. Accessing the Flask App

Once the container is running, access the Flask application at http://localhost:3000. πŸŽ‰

πŸ“‹ Useful Docker Commands

Here are some essential Docker commands to manage your containers and images:

  • List Docker images:

    docker images
  • List running containers:

    docker ps
  • List all containers (including stopped ones):

    docker ps -a
  • Remove a Docker image:

    docker rmi -f image-name
  • View logs from a container:

    docker logs container-id
  • Open an interactive terminal session inside a container:

    docker exec -it container-id /bin/bash

Demo

flask-app-google-chrome-2024-08-30-00-53-19_bLrTlJWH.mp4

About

This project shows how to Dockerize a Flask app. 🐳 By containerizing, you get consistent deployment and easier management. It integrates AI services for handling different data types, demonstrating Docker's power and flexibility. πŸš€

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published