Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Step 4: Environment

Set up environment variables and application configuration for your container.

Quick Templates

Pre-configured environment variable templates for common frameworks:

Node.js Applications

  • NODE_ENV: Environment mode (development/production)
  • PORT: Application port
  • NPMCONFIGPRODUCTION: Skip dev dependencies in production

Database Configuration

  • DATABASE_URL 🔒: Database connection string (encrypted)
  • REDIS_URL 🔒: Redis connection string (encrypted)
  • DB_HOST: Database hostname
  • DB_PORT: Database port
  • ENCRYPTION_KEY 🔒: Data encryption key (encrypted)

Application Settings

  • DEBUG: Enable debug mode
  • LOG_LEVEL: Logging verbosity level
  • MAX_CONNECTIONS: Maximum concurrent connections
  • TIMEOUT: Request timeout (milliseconds)

Custom Environment Variables

Add application-specific configuration:

  1. Variable Name: Use UPPERCASE with underscores
  2. Variable Value: Enter the configuration value
  3. Security: Sensitive values are automatically detected and encrypted

Example:

API_KEY=your-secret-api-key
MAX_WORKERS=4
CACHE_TTL=3600
DATABASE_URL=postgresql://user:pass@host:5432/db

Bulk Import

For applications with many environment variables:

  1. Click Show Bulk Import
  2. Paste variables in KEY=value format
  3. Variables are automatically parsed and added

Bulk Import Format:

API_KEY=abc123
DB_HOST=localhost
DB_PORT=5432
MAX_WORKERS=4
LOG_LEVEL=info

Common Environment Variable Patterns

Database Connections

DATABASE_URL=postgresql://user:password@host:port/database
DB_HOST=localhost
DB_PORT=5432
DB_NAME=myapp
DB_USER=appuser
DB_PASSWORD=securepassword

Redis Configuration

REDIS_URL=redis://localhost:6379/0
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=redispassword

Application Settings

APP_ENV=production
APP_DEBUG=false
APP_URL=https://myapp.com
APP_NAME="My Application"
APP_VERSION=1.0.0

API Configuration

API_KEY=your-api-key
API_SECRET=your-api-secret
API_TIMEOUT=30000
API_RATE_LIMIT=1000

Security Settings

JWT_SECRET=your-jwt-secret
ENCRYPTION_KEY=your-encryption-key
SSL_ENABLED=true
CORS_ORIGIN=https://frontend.com

Framework-Specific Examples

Django Applications

DJANGO_SETTINGS_MODULE=myapp.settings.production
SECRET_KEY=django-secret-key
DEBUG=False
ALLOWED_HOSTS=myapp.com,www.myapp.com
DATABASE_URL=postgres://user:pass@host:5432/db

Flask Applications

FLASK_ENV=production
FLASK_APP=app.py
SECRET_KEY=flask-secret-key
DATABASE_URL=postgresql://user:pass@host:5432/db

Express.js Applications

NODE_ENV=production
PORT=3000
SESSION_SECRET=session-secret
DATABASE_URL=mongodb://user:pass@host:27017/db

Spring Boot Applications

SPRING_PROFILES_ACTIVE=production
SERVER_PORT=8080
SPRING_DATASOURCE_URL=jdbc:postgresql://host:5432/db
SPRING_DATASOURCE_USERNAME=user
SPRING_DATASOURCE_PASSWORD=password

Environment Variable Best Practices

Naming Conventions

  • Use UPPERCASE: Standard convention for environment variables
  • Use Underscores: Separate words with underscores (DATABASE_URL)
  • Avoid Spaces: No spaces or special characters in variable names
  • Descriptive Names: Use names that clearly indicate purpose

Security Guidelines

  • Sensitive Data: Store passwords, API keys, and secrets securely
  • No Hardcoding: Never hardcode secrets in container images
  • Encryption: Platform automatically encrypts sensitive values
  • Access Control: Limit who can view/modify sensitive variables

Configuration Management

  • Environment Separation: Use different values per environment (dev/staging/prod)
  • Validation: Validate required variables at application startup
  • Documentation: Document the purpose and format of each variable
  • Defaults: Provide sensible defaults where appropriate

Common Patterns

  • Database URLs: Use connection strings for database configuration
  • Feature Flags: Use boolean values for feature toggles
  • Resource Limits: Configure timeouts, limits, and thresholds
  • External Services: Store API endpoints and credentials

Security Considerations

Sensitive Data Handling

  • Platform automatically detects and encrypts sensitive values
  • Variables containing "password", "secret", "key", "token" are encrypted
  • Encrypted values are not visible in logs or exports
  • Use descriptive names that indicate the variable's purpose

Best Practices for Secrets

  • Rotation: Regularly rotate sensitive credentials
  • Minimal Scope: Use service-specific credentials with limited permissions
  • Monitoring: Monitor access to sensitive configuration
  • Backup: Ensure secure backup of critical configuration

Troubleshooting Environment Issues

Common Problems

  • Missing Variables: Application fails due to undefined required variables
  • Incorrect Format: Variables not in expected format (URLs, JSON, etc.)
  • Encoding Issues: Special characters in variable values
  • Case Sensitivity: Mismatched variable name casing

Debugging Steps

  1. Check application logs for environment variable errors
  2. Verify variable names match application expectations
  3. Validate variable values and formats
  4. Test with minimal configuration first
  5. Use container console to inspect environment

Next: Proceed to Step 5 to configure persistent storage and data management.