A simple FastAPI application containerized with Docker.
dockploy/
├── app/
│ ├── __init__.py
│ └── main.py # FastAPI application
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── .dockerignore # Docker ignore file
└── README.md # This file
- 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
GET /- Welcome messageGET /health- Health check endpointGET /items/{item_id}- Get item by ID with optional query parameter
docker build -t fastapi-app .docker run -d -p 8000:8000 --name fastapi-container fastapi-app# 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=testdocker stop fastapi-container
docker rm fastapi-container-
Install dependencies:
pip install -r requirements.txt
-
Run the application:
uvicorn app.main:app --host 0.0.0.0 --port 8000
Once the application is running, visit:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
The Dockerfile includes:
- Python 3.12 slim base image
- Security best practices (non-root user)
- Health checks
- Optimized layer caching
- Minimal attack surface
This application is configured for automatic deployment on Dockploy.
-
Connect GitHub to Dockploy:
- Go to your Dockploy dashboard
- Navigate to Settings > Git
- Connect your GitHub account
- Authorize Dockploy to access your repositories
-
Create Application in Dockploy:
- Click "New" > "Create new App"
- Name:
fastapi-test-tmp - Select your GitHub repository
- Choose the main branch
- Enable "Auto Deploy"
-
Deploy:
- Push any changes to the main branch
- Dockploy will automatically build and deploy your application
- Access your app at the provided Dockploy URL
Run the deployment script to test locally:
./deploy.shThis script will:
- Build the Docker image
- Test the container locally
- Verify all endpoints are working
- Clean up test containers
PYTHONDONTWRITEBYTECODE=1- Prevents Python from writing .pyc filesPYTHONUNBUFFERED=1- Ensures Python output is sent straight to terminalPYTHONPATH=/app- Sets the Python path for module imports