Skip to content

wtoloza-dev/fastapi-test-tmp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI Docker Application

A simple FastAPI application containerized with Docker.

Project Structure

dockploy/
├── app/
│   ├── __init__.py
│   └── main.py          # FastAPI application
├── requirements.txt     # Python dependencies
├── Dockerfile          # Docker configuration
├── .dockerignore       # Docker ignore file
└── README.md           # This file

Features

  • FastAPI Application: Simple REST API with multiple endpoints
  • Docker Support: Fully containerized application
  • Security: Non-root user execution
  • Health Checks: Built-in health monitoring
  • Python 3.12: Latest Python version support

API Endpoints

  • GET / - Welcome message
  • GET /health - Health check endpoint
  • GET /items/{item_id} - Get item by ID with optional query parameter

Quick Start

Build the Docker Image

docker build -t fastapi-app .

Run the Container

docker run -d -p 8000:8000 --name fastapi-container fastapi-app

Test the API

# Test the root endpoint
curl http://localhost:8000/

# Test the health endpoint
curl http://localhost:8000/health

# Test the items endpoint
curl http://localhost:8000/items/123?q=test

Stop the Container

docker stop fastapi-container
docker rm fastapi-container

Development

Run Locally (without Docker)

  1. Install dependencies:

    pip install -r requirements.txt
  2. Run the application:

    uvicorn app.main:app --host 0.0.0.0 --port 8000

Access the Interactive API Documentation

Once the application is running, visit:

Docker Configuration

The Dockerfile includes:

  • Python 3.12 slim base image
  • Security best practices (non-root user)
  • Health checks
  • Optimized layer caching
  • Minimal attack surface

Dockploy Deployment

This application is configured for automatic deployment on Dockploy.

Deploy to Dockploy

  1. Connect GitHub to Dockploy:

    • Go to your Dockploy dashboard
    • Navigate to Settings > Git
    • Connect your GitHub account
    • Authorize Dockploy to access your repositories
  2. Create Application in Dockploy:

    • Click "New" > "Create new App"
    • Name: fastapi-test-tmp
    • Select your GitHub repository
    • Choose the main branch
    • Enable "Auto Deploy"
  3. Deploy:

    • Push any changes to the main branch
    • Dockploy will automatically build and deploy your application
    • Access your app at the provided Dockploy URL

Local Testing Before Deployment

Run the deployment script to test locally:

./deploy.sh

This script will:

  • Build the Docker image
  • Test the container locally
  • Verify all endpoints are working
  • Clean up test containers

Environment Variables

  • PYTHONDONTWRITEBYTECODE=1 - Prevents Python from writing .pyc files
  • PYTHONUNBUFFERED=1 - Ensures Python output is sent straight to terminal
  • PYTHONPATH=/app - Sets the Python path for module imports

About

Simple FastAPI application with Docker support

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published