Skip to main content

Overview

Environment variables provide runtime configuration for your applications. Dokploy supports environment variables at multiple levels with inheritance and secret management.

Variable Hierarchy

Dokploy applies environment variables in this order (later overrides earlier):
1

Project Variables

Shared across all applications in a project:
2

Environment Variables

Specific to an environment (dev, staging, prod):
3

Application Variables

Specific to individual applications:
Highest priority - overrides project and environment variables.

Configuration

Basic Variables

Set environment variables in the Dokploy UI or via API:
Format:
  • One variable per line
  • Use KEY=value format
  • No quotes needed around values
  • Empty lines are ignored

Multi-line Values

For values containing newlines:

Special Characters

Escape special characters in values:

Common Use Cases

Database Connection

Configure database connectivity:
Use internal Docker network hostnames (e.g., postgres, redis) instead of localhost or IP addresses.

Framework-Specific

Configure popular frameworks:

Third-Party Services

Configure external service integrations:

Environment File Generation

Dokploy can create a .env file in your application container:
When enabled:
  • Creates /app/.env in the container
  • Contains all environment variables
  • Useful for applications that read from .env files
  • Works alongside environment variables
Disable createEnvFile if your application doesn’t need it. Environment variables are always available regardless of this setting.

Build-Time vs Runtime

Build Arguments

Available during Docker build only:
Use for:
  • Compilation flags
  • Build-time URLs (Next.js NEXT_PUBLIC_*)
  • Version numbers
  • Build optimizations
Example in Dockerfile:

Environment Variables

Available at runtime only:
Use for:
  • Database connections
  • API keys
  • Runtime configuration
  • Feature flags
Most configuration should use environment variables, not build arguments. Build arguments are baked into the image.

Preview Deployment Variables

Set different variables for preview deployments:
Preview variables override production variables in preview deployments.

Variable Interpolation

Reference other variables in values:
Variable interpolation is handled by your application or shell, not by Dokploy.

Secret Management

Marking as Secret

Mark sensitive variables as secrets in the UI:
  1. Add variable in Dokploy dashboard
  2. Click the lock icon next to the variable
  3. Value is encrypted and hidden

Build Secrets

For secrets needed during build:
Use in Dockerfile:
Build secrets are:
  • Not stored in image layers
  • Not available at runtime
  • More secure than build arguments

Best Practices

Always use environment variables for secrets, never hardcode in source.
Update secrets periodically:
  1. Generate new secret
  2. Update in Dokploy
  3. Redeploy application
  4. Revoke old secret
Frequency: Every 90 days for high-security apps.
Use different secrets for each environment:

Variable Validation

Validate required variables in your application:

Accessing Variables

In Application Code

In Docker Compose

Reference Dokploy environment variables in compose files:

Dynamic Configuration

Update variables without redeploying:
Variable changes require a redeploy to take effect. Use the redeploy endpoint (not deploy) to avoid rebuilding from source.

Troubleshooting

Symptoms: Application can’t read environment variableSolutions:
  1. Verify variable is set:
  2. Check variable format:
  3. Ensure application reads from correct source:
Symptoms: Variable has unexpected valueSolutions:
  1. Check variable hierarchy:
    • Application variables override environment variables
    • Environment variables override project variables
  2. Verify no hardcoded values:
  3. Ensure redeploy after changes:
Symptoms: Variables with special characters breakSolutions:
  1. Escape special characters:
  2. Use base64 for complex values:
Symptoms: Build args are undefined at runtimeSolutions: Build arguments are build-time only. Use environment variables:
Or configure in Dokploy:

API Reference

Save Environment Variables

Update Application

Next Steps

Build Configuration

Configure build process and arguments

Git Integration

Automate deployments from Git

Security

Security best practices

Deployments Overview

Learn about deployment workflows