Skip to content

search4asraful/python-oracle-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

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

Repository files navigation

🌐 Oracle Books Management - Web Interface

A modern, responsive web application for managing books in an Oracle database using Flask, Bootstrap, and Docker.

πŸ“ Project Structure

python-oracle-docker/
β”œβ”€β”€ Dockerfile                    # Updated with Flask
β”œβ”€β”€ docker-compose.yml           # Updated with web port mapping
β”œβ”€β”€ app.py                      # Flask web application
β”œβ”€β”€ templates/                  # HTML templates directory
β”‚   β”œβ”€β”€ base.html              # Base template with navigation
β”‚   β”œβ”€β”€ index.html             # Main books listing page
β”‚   β”œβ”€β”€ add_book.html          # Add new book form
β”‚   └── edit_book.html         # Edit existing book form
└── README.md                  # This file

πŸš€ Getting Started

1️⃣ Clone and Setup

git clone https://github.com/search4asraful/python-oracle-docker.git
cd python-oracle-docker

2️⃣ Build and Start Services

# Build the images
docker compose build

# Start Oracle database in background
docker compose up -d oracle-db

# Wait for database to be ready (check logs)
docker compose logs -f oracle-db

# Start the web application
docker compose up -d web-app

3️⃣ Access the Web Interface

Open your browser and go to:

4️⃣ Initialize Database

Click on "Reset DB" in the navigation menu or visit http://localhost:5000/init to create the books table.

🎯 Features

πŸ“± Responsive Web Interface

  • Modern Bootstrap 5 Design: Professional, mobile-friendly interface
  • Real-time Statistics: Dashboard showing total, available, and unavailable books
  • Interactive Forms: Form validation and user feedback
  • Flash Messages: Success/error notifications with auto-dismiss

πŸ”§ CRUD Operations

  • πŸ“– View Books: Paginated list with search and filter options
  • βž• Add Books: Form with validation and quick-fill examples
  • ✏️ Edit Books: In-place editing with current data display
  • πŸ—‘οΈ Delete Books: Confirmation dialogs for safe deletion

πŸ›‘οΈ Error Handling

  • Database Connection: Graceful handling of connection failures
  • Input Validation: Client and server-side validation
  • User Feedback: Clear error messages and success confirmations

🌟 Web Interface Screenshots

Main Dashboard

  • Clean, modern interface showing book statistics
  • Responsive card layout with gradient backgrounds
  • Quick action buttons and navigation

Add/Edit Forms

  • User-friendly forms with real-time validation
  • Character count indicators
  • Quick-fill examples for faster data entry

Books Table

  • Professional table design with hover effects
  • Status badges (Available/Unavailable)
  • Action buttons for edit/delete operations

πŸ“‘ API Endpoints

Method Endpoint Description
GET / Main books listing page
GET /add Add new book form
POST /add Submit new book data
GET /edit/<id> Edit book form
POST /edit/<id> Update book data
GET /delete/<id> Delete book (with confirmation)
GET /init Initialize database tables
GET /health API health check

πŸ”§ Development Commands

# View application logs
docker compose logs -f web-app

# View database logs
docker compose logs -f oracle-db

# Restart web application only
docker compose restart web-app

# Stop all services
docker compose down

# Stop and remove volumes (fresh start)
docker compose down -v

🎨 Customization

Styling

  • Edit templates/base.html to modify the overall theme
  • CSS variables for easy color scheme changes
  • Bootstrap 5 utilities for rapid customization

Database Schema

Modify the table structure in app.py:

cursor.execute("""
CREATE TABLE books (
    id NUMBER GENERATED BY DEFAULT AS IDENTITY,
    title VARCHAR2(100),
    author VARCHAR2(100),
    available CHAR(1),
    -- Add more columns here
    PRIMARY KEY (id)
)
""")

🌐 Production Deployment

Environment Variables

export FLASK_ENV=production
export ORACLE_USER=your_user
export ORACLE_PASSWORD=your_password
export ORACLE_HOST=your_host

Docker Production Build

# Use production WSGI server
RUN pip install gunicorn

# Run with Gunicorn
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"]

πŸ” Troubleshooting

Common Issues

  1. Database Connection Failed

    • Check if Oracle container is running: docker compose ps
    • Verify Oracle logs: docker compose logs oracle-db
    • Wait for healthcheck to pass (can take 2-3 minutes)
  2. Web Interface Not Loading

    • Check Flask container logs: docker compose logs web-app
    • Verify port 5000 is not in use: netstat -an | grep 5000
  3. Template Not Found

    • Ensure templates directory exists and contains all HTML files
    • Check file permissions and mounting in docker-compose.yml

Port Configuration

If port 5000 is already in use, change it in docker-compose.yml:

ports:
  - "8080:5000"  # Use port 8080 instead

πŸ“ License

MIT License - feel free to use and modify for your projects.


πŸŽ‰ Features Overview

This web interface transforms the command-line Oracle database operations into a full-featured web application with:

  • Professional UI/UX with Bootstrap 5
  • Responsive design that works on all devices
  • Real-time form validation with visual feedback
  • Interactive dashboard with statistics and quick actions
  • Error handling with user-friendly messages
  • RESTful endpoints for API integration
  • Docker containerization for easy deployment

Perfect for learning Oracle database operations, Flask web development, and Docker containerization!

About

Dockerized Python project demonstrating CRUD operations with Oracle Database using oracledb/cx_Oracle, fully portable across Windows, Linux, and Mac.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors