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:- One variable per line
- Use
KEY=valueformat - 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:Framework-Specific
Configure popular frameworks:- Next.js
- Django
- Laravel
- Rails
- Express
- FastAPI
Third-Party Services
Configure external service integrations:Environment File Generation
Dokploy can create a.env file in your application container:
- Creates
/app/.envin the container - Contains all environment variables
- Useful for applications that read from
.envfiles - Works alongside environment variables
Build-Time vs Runtime
Build Arguments
Available during Docker build only:- Compilation flags
- Build-time URLs (Next.js
NEXT_PUBLIC_*) - Version numbers
- Build optimizations
Environment Variables
Available at runtime only:- 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: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:- Add variable in Dokploy dashboard
- Click the lock icon next to the variable
- Value is encrypted and hidden
Build Secrets
For secrets needed during build:- Not stored in image layers
- Not available at runtime
- More secure than build arguments
Best Practices
Never Commit Secrets
Never Commit Secrets
Use Strong Secrets
Use Strong Secrets
Rotate Regularly
Rotate Regularly
Update secrets periodically:
- Generate new secret
- Update in Dokploy
- Redeploy application
- Revoke old secret
Separate Environments
Separate Environments
Use different secrets for each environment:
Variable Validation
Validate required variables in your application:Accessing Variables
In Application Code
- Node.js
- Python
- Go
- PHP
- Ruby
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
Variable Not Available
Variable Not Available
Symptoms: Application can’t read environment variableSolutions:
- Verify variable is set:
- Check variable format:
- Ensure application reads from correct source:
Variable Contains Wrong Value
Variable Contains Wrong Value
Symptoms: Variable has unexpected valueSolutions:
- Check variable hierarchy:
- Application variables override environment variables
- Environment variables override project variables
- Verify no hardcoded values:
- Ensure redeploy after changes:
Special Characters Causing Issues
Special Characters Causing Issues
Symptoms: Variables with special characters breakSolutions:
- Escape special characters:
- Use base64 for complex values:
Build Arguments Not Working at Runtime
Build Arguments Not Working at Runtime
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