📖 Looking for karrio's legacy docs? Visit docs.karrio.io

Environment Variables

This page provides a comprehensive reference for all environment variables you can use to configure your self-hosted Karrio instance.

Core Configuration

These variables control the basic functionality of your Karrio installation.

VariableDescriptionDefaultRequired
SECRET_KEYDjango secret key used for cryptographic signingRandom stringYes
DEBUG_MODEEnable debug mode (not recommended in production)FalseNo
USE_HTTPSEnable HTTPS supportFalseNo
DOMAINYour domain namelocalhostYes (for production)
ALLOWED_HOSTSComma-separated list of allowed hosts*No

Database Configuration

These variables configure the PostgreSQL database connection.

VariableDescriptionDefaultRequired
DATABASE_ENGINEDatabase engine to usepostgresql_psycopg2Yes
DATABASE_NAMEDatabase namedbYes
DATABASE_USERNAMEDatabase userpostgresYes
DATABASE_PASSWORDDatabase passwordpostgresYes
DATABASE_HOSTDatabase hostdbYes
DATABASE_PORTDatabase port5432Yes

Redis Configuration

Redis is used for caching and background task management.

VariableDescriptionDefaultRequired
REDIS_HOSTRedis hostredisYes
REDIS_PORTRedis port6379Yes
REDIS_PASSWORDRedis password (if required)NoneNo
REDIS_DBRedis database number1No

API Configuration

These variables configure the Karrio API server.

VariableDescriptionDefaultRequired
KARRIO_HTTP_PORTHTTP port for the API server5002No
KARRIO_PUBLIC_URLPublic URL for the APIhttp://localhost:5002Yes (for production)
KARRIO_WORKERSNumber of API workers2No
BACKGROUND_WORKERSNumber of background workers2No
DETACHED_WORKERRun worker in detached modeFalseNo

Dashboard Configuration

These variables configure the Karrio dashboard.

VariableDescriptionDefaultRequired
DASHBOARD_PORTHTTP port for the dashboard3000No
DASHBOARD_URLPublic URL for the dashboardhttp://localhost:3000Yes (for production)
NEXTAUTH_SECRETSecret key for NextAuth (dashboard auth)Same as JWT_SECRETYes
JWT_SECRETSecret key for JWT tokensRandom stringYes

Email Configuration

These variables configure email sending for notifications.

VariableDescriptionDefaultRequired
EMAIL_HOSTSMTP server hostNoneNo
EMAIL_PORTSMTP server port587No
EMAIL_HOST_USERSMTP usernameNoneNo
EMAIL_HOST_PASSWORDSMTP passwordNoneNo
EMAIL_USE_TLSUse TLS for SMTP connectionTrueNo
DEFAULT_FROM_EMAILDefault sender email addressnoreply@localhostNo

Admin Account

These variables configure the default admin account created on first startup.

VariableDescriptionDefaultRequired
ADMIN_EMAILAdmin user emailadmin@example.comNo
ADMIN_PASSWORDAdmin user passworddemoNo

File Storage

These variables configure where files are stored.

VariableDescriptionDefaultRequired
WORK_DIRWorking directory for the API/karrio/appNo
LOG_DIRDirectory for log files/karrio/logNo
WORKER_DB_DIRDirectory for worker databases/karrio/dataNo
STATIC_ROOT_DIRDirectory for static files/karrio/staticNo

Advanced Configuration

These variables enable advanced features and optimizations.

VariableDescriptionDefaultRequired
LOG_LEVELLogging level (DEBUG, INFO, WARNING, ERROR)INFONo
SENTRY_DSNSentry DSN for error monitoringNoneNo
CORS_ALLOWED_ORIGINSComma-separated list of allowed CORS origins*No
MAX_UPLOAD_SIZEMaximum upload size in MB10No
THROTTLE_RATEAPI throttle rate (requests/minute)NoneNo
CACHE_TIMEOUTCache timeout in seconds300No

Example .env File

Here’s a complete example of a .env file for a production deployment:

Core settings
1SECRET_KEY=your_secure_secret_key 2DEBUG_MODE=False 3USE_HTTPS=True 4DOMAIN=karrio.yourdomain.com 5 6# Database settings 7DATABASE_ENGINE=postgresql_psycopg2 8DATABASE_NAME=karrio 9DATABASE_USERNAME=karrio_user 10DATABASE_PASSWORD=your_secure_db_password 11DATABASE_HOST=db 12DATABASE_PORT=5432 13 14# Redis settings 15REDIS_HOST=redis 16REDIS_PORT=6379 17 18# API settings 19KARRIO_PUBLIC_URL=https://api.yourdomain.com 20KARRIO_WORKERS=4 21BACKGROUND_WORKERS=2 22DETACHED_WORKER=True 23 24# Dashboard settings 25DASHBOARD_URL=https://app.yourdomain.com 26JWT_SECRET=your_secure_jwt_secret 27 28# Email settings 29EMAIL_HOST=smtp.provider.com 30EMAIL_PORT=587 31EMAIL_HOST_USER=your_email@provider.com 32EMAIL_HOST_PASSWORD=your_email_password 33EMAIL_USE_TLS=True 34DEFAULT_FROM_EMAIL=karrio@yourdomain.com 35 36# Admin account 37ADMIN_EMAIL=admin@yourdomain.com 38ADMIN_PASSWORD=your_secure_admin_password 39 40# Carrier credentials - USPS example 41USPS_USERNAME=your_usps_username 42USPS_PASSWORD=your_usps_password 43USPS_TEST_MODE=False

Environment Variables in Docker

When using Docker, there are multiple ways to set environment variables:

  1. Docker Compose: Add environment variables in the docker-compose.yml file under the appropriate service:
1services: 2 api: 3 environment: 4 SECRET_KEY: your_secure_secret_key 5 DEBUG_MODE: "False" 6 # other variables
  1. Environment Files: Use an .env file in the same directory as your docker-compose.yml file. Docker Compose will automatically load these variables.

  2. Command Line: Pass variables through the command line when running containers:

1docker-compose up -d -e SECRET_KEY=your_secure_secret_key

Best Practices

  1. Security: Never commit sensitive environment variables to your repository. Use .env files that are added to your .gitignore.

  2. Production vs. Development: Maintain separate environment files for different environments.

  3. Secret Management: For production deployments, consider using a secret management service like AWS Secrets Manager, GCP Secret Manager, or HashiCorp Vault.

  4. Documentation: Document any custom environment variables you create for your specific deployment or extensions.