Skip to main content
This guide covers deploying FKApi using Docker containers for simplified setup and deployment. Docker provides a consistent environment across development and production.

Overview

FKApi includes a complete Docker setup with:
  • Multi-stage Dockerfile for optimized images
  • docker-compose.yml with all services
  • Service profiles for flexible deployments
  • Health checks for all containers
  • Volume management for data persistence

Prerequisites

Before you begin, install:
  • Docker 20.10 or higher
  • Docker Compose V2 or higher
  • Git

Quick Start

Docker Architecture

Dockerfile

FKApi uses a multi-stage build for optimization:
Key features:
  • Multi-stage build: Reduces final image size
  • Layer caching: Faster rebuilds
  • Health checks: Automatic container monitoring
  • Dynamic command: Development vs production mode

Services

The docker-compose.yml defines these services:

Core Services (Always Active)

Database (db)
Redis (redis)
Web Application (web)
Celery Worker (celery)
Celery Beat (celerybeat)
Flower (flower)

Monitoring Services (Optional)

Monitoring services use the monitoring profile: Prometheus (prometheus)

Service Profiles

FKApi uses Docker Compose profiles for flexible deployments:

Default Profile (Minimal Setup)

Start only core services:
Includes:
  • PostgreSQL database
  • Redis cache
  • Django web application
  • Celery worker
  • Celery beat
  • Flower

Monitoring Profile

Add monitoring stack:
Adds:
  • Prometheus (metrics collection)
  • Redis Exporter (Redis metrics)
  • PostgreSQL Exporter (database metrics)
See the Monitoring guide for setup details.

Common Operations

Viewing Logs

Restarting Services

Rebuilding Images

Running Commands

Managing Data

Production Deployment

Security Hardening

For production, update your .env:

Using Docker Secrets

For sensitive data, use Docker secrets:

Resource Limits

Set resource limits for production:

Health Checks

All services include health checks. Monitor with:

Troubleshooting

Container Fails to Start

Check logs:
Common causes:
  • Environment variable errors
  • Database not ready (increase start_period in health check)
  • Port conflicts
  • Permission issues

Database Connection Errors

Verify database is running:
Check connection from web:

Redis Connection Errors

Test Redis connection:
Check from web container:

Port Already in Use

Change ports in .env:
Or stop conflicting services:

Out of Disk Space

Clean up Docker:

Best Practices

  • Never commit .env files
  • Use .env.example as template
  • Use Docker secrets for production
  • Document all variables
  • Validate required variables on startup
  • Use named volumes for data
  • Regular database backups
  • Test restore procedures
  • Monitor disk usage
  • Implement backup rotation
  • Use Docker networks for service isolation
  • Expose only necessary ports
  • Use reverse proxy (nginx) for production
  • Enable HTTPS/TLS
  • Implement rate limiting
  • Configure log rotation
  • Use centralized logging
  • Monitor log volume
  • Set appropriate log levels
  • Parse logs for errors

Next Steps

Caching Strategy

Optimize performance with Redis caching

Monitoring

Set up Prometheus and Grafana