Overview
The VidaPlus API can be easily deployed using Docker, which provides a consistent and isolated environment for running the application. This guide covers building Docker images and running containers for production deployment.Prerequisites
Before you begin, ensure you have:- Docker installed on your machine
- Basic familiarity with Docker commands
- A copy of the VidaPlus API source code
Dockerfile Configuration
The VidaPlus API uses a Python 3.13 slim image as its base. Here’s the Dockerfile structure:Key Configuration Points
- Base Image: Uses
python:3.13-slimfor a lightweight Python environment - Poetry Configuration: Disables virtual environment creation with
POETRY_VIRTUALENVS_CREATE=false - Dependencies: Installs production dependencies only (excludes dev dependencies)
- Port Exposure: Exposes port 8000 for the FastAPI application
- Entry Point: Runs Uvicorn server with the FastAPI app
Building the Docker Image
Build the Image
Build the Docker image with a specific tag:This command builds an image named
vidaplus-api using the Dockerfile in the current directory.Running the Container
Basic Container Setup
To run the VidaPlus API container with basic configuration:-d: Run container in detached mode (background)--name vidaplus-api: Assign a name to the container-p 8000:8000: Map port 8000 on host to port 8000 in container
Running with Environment Variables
The VidaPlus API requires environment variables for database connection and JWT authentication. Pass them using the-e flag or an environment file:
Create a
.env file based on .env.example from the repository. The required environment variables are:DATABASE_URL: PostgreSQL connection stringSECRET_KEY: Secret key for JWT token generationALGORITHM: JWT algorithm (typically HS256)ACCESS_TOKEN_EXPIRE_MINUTES: Token expiration time in minutes
Accessing the API
Once the container is running, you can access:API Endpoints
Main API at
http://localhost:8000Interactive Documentation
Swagger UI at
http://localhost:8000/docsAlternative Docs
ReDoc at
http://localhost:8000/redocOpenAPI Schema
JSON schema at
http://localhost:8000/openapi.jsonContainer Management
Viewing Container Logs
Stopping the Container
Starting a Stopped Container
Restarting the Container
Removing the Container
Production Deployment Considerations
Database Connection
For production deployments, ensure yourDATABASE_URL points to a production PostgreSQL database. If running PostgreSQL in another Docker container, use Docker networking:
Running Migrations
Before starting the API, run database migrations inside the container:Health Checks
Add health checks to your Docker run command:Volume Persistence
If you need to persist data or logs, use Docker volumes:Troubleshooting
Container Won’t Start
- Check container logs:
docker logs vidaplus-api - Verify environment variables are set correctly
- Ensure the database is accessible from the container
Port Already in Use
If port 8000 is already in use, map to a different host port:http://localhost:8080
Database Connection Issues
- Verify
DATABASE_URLformat:postgresql://username:password@host:port/database - If using Docker networks, use container names instead of
localhost - Check that the database container is running and healthy
Next Steps
Database Migrations
Learn how to manage database migrations with Alembic
Testing
Run tests to ensure your deployment is working correctly