Environment Variable Format
All configuration file settings can be overridden using environment variables with this format:Naming Convention
- Prefix:
GF_ - Section name: Uppercase with underscores replacing dots
- Key name: Uppercase with underscores replacing hyphens
Examples
| Configuration File | Environment Variable |
|---|---|
[server] http_port | GF_SERVER_HTTP_PORT |
[database] type | GF_DATABASE_TYPE |
[database] max_open_conn | GF_DATABASE_MAX_OPEN_CONN |
[auth.github] client_id | GF_AUTH_GITHUB_CLIENT_ID |
[auth.google] enabled | GF_AUTH_GOOGLE_ENABLED |
[security] admin_password | GF_SECURITY_ADMIN_PASSWORD |
[smtp] from_address | GF_SMTP_FROM_ADDRESS |
Common Environment Variables
Server Configuration
Database Configuration
Security Configuration
Authentication Providers
GitHub OAuth:SMTP Configuration
Paths Configuration
Logging Configuration
User Management
Analytics Configuration
Docker Environment Variables
When running Grafana in Docker, pass environment variables using the-e flag:
.env file with Docker Compose:
Kubernetes Deployment
For Kubernetes, use ConfigMaps and Secrets:Special Character Handling
When using environment variables with special characters, proper shell quoting may be required:Verifying Environment Variables
To verify which environment variables are being used:Precedence and Overrides
Configuration values are applied in this order (later overrides earlier):- Default values from
conf/defaults.ini - Custom configuration from
conf/custom.ini - Environment variables (highest priority)
- Command-line arguments
Best Practices
- Use environment variables for secrets - Never commit passwords to configuration files
- Document your variables - Keep a list of required environment variables
- Use secret management - Leverage Kubernetes Secrets, AWS Secrets Manager, or HashiCorp Vault
- Validate before deployment - Test configuration in non-production environments
- Avoid hardcoding - Use variable interpolation where possible
- Use .env files locally - Keep development configuration consistent
- Set defaults - Provide sensible defaults for non-sensitive variables
Troubleshooting
Environment variables not taking effect:- Verify the variable name follows the
GF_SECTION_KEYformat - Check for typos in variable names
- Ensure variables are exported (use
exportin shell) - Restart Grafana after changing environment variables
- Check for proper quoting of special characters
- Verify boolean values are
trueorfalse(lowercase) - Ensure numeric values don’t have quotes