Skip to content

engripaye/dockerized-flask-rest-api

Repository files navigation

🐳 Dockerized Flask REST API

A lightweight Flask-based REST API packaged and deployed inside a Docker container. This project demonstrates modern backend development practices, including environment reproducibility, dependency management, and containerized deployment.


πŸš€ Features

  • Flask REST API – Simple and clean endpoints for managing users or tasks.
  • Dockerized Environment – Fully containerized using Docker for consistent setup across machines.
  • Dependency Isolation – Uses requirements.txt and Docker layers for clean dependency management.
  • Scalable Design – Easily extendable for production use with Docker Compose or Kubernetes.

πŸ“ Project Structure

dockerized-flask-api/
β”‚
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ routes.py          # API endpoints
β”‚   └── models.py          # Simple data structure / logic
β”‚
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ Dockerfile             # Docker build configuration
β”œβ”€β”€ .dockerignore          # Files ignored during Docker build
β”œβ”€β”€ README.md              # Project documentation
└── run.py                 # Entry point for the Flask app

βš™οΈ Setup & Usage

1. Clone the repository

git clone https://github.com/yourusername/dockerized-flask-api.git
cd dockerized-flask-api

2. Build the Docker image

docker build -t flask-api .

3. Run the container

docker run -d -p 5000:5000 flask-api

4. Test the API

Visit: http://localhost:5000

Example endpoint:

curl http://localhost:5000/api/todos

🧩 Example Endpoint

GET /api/todos Returns all todos in JSON format.

POST /api/todos Creates a new todo item.

Example JSON payload:

{
  "task": "Learn Docker",
  "completed": false
}

🧠 Key Learnings

  • How to containerize Python/Flask apps using Docker.
  • Managing dependencies and environments for reproducibility.
  • Building RESTful APIs with Flask.
  • Preparing apps for scalable deployment pipelines.

🧰 Tech Stack

Tool Purpose
Python 3.10+ Backend logic
Flask REST API framework
Docker Containerization
JSON API data format

πŸ“Έ Architecture Diagram

+---------------------+
|     Client App      |
| (Postman / Browser) |
+----------+----------+
           |
           v
+---------------------+
|     Flask API       |
|   (Python / Flask)  |
+----------+----------+
           |
           v
+---------------------+
|     Docker Engine   |
| (Isolated Container)|
+---------------------+

πŸ§ͺ Example Dockerfile

# Use official lightweight Python image
FROM python:3.10-slim

# Set work directory
WORKDIR /app

# Copy dependencies
COPY requirements.txt .

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy project files
COPY . .

# Expose the app port
EXPOSE 5000

# Run the application
CMD ["python", "run.py"]

πŸ‘¨β€πŸ’» Author

Olabowale Babatunde Ipaye πŸ’Ό Backend Developer | Cloud & DevOps Enthusiast 🌐 LinkedIn β€’ GitHub


🏁 Future Improvements

  • Add database integration (SQLite or PostgreSQL).
  • Implement user authentication.
  • Deploy using Docker Compose or Kubernetes.

Would you like me to also generate the code files (app/routes.py, run.py, and Dockerfile) so you can instantly run and push this to GitHub? I can make it simple, clean, and production-ready.

About

🐳A lightweight Flask-based REST API packaged and deployed inside a Docker container.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published