Environment Variables in DeployStack
DeployStack supports environment variables for your Docker configurations through the .deploystack/env file. This allows you to manage configuration values separately from your Docker files and maintain consistency across deployments.
Adding Environment Variables
Create an env file in your .deploystack directory:
your-repository/
├── .deploystack/
│ ├── env
└── README.md
Your env file should follow the standard environment file format:
# .deploystack/env
DB_USERNAME=myuser
DB_PASSWORD=mysecretpassword
DB_DATABASE=mydatabase
Using Environment Variables
In Docker Compose
Reference environment variables in your docker-compose.yml using the ${VARIABLE_NAME} syntax:
services:
db:
image: mariadb:11.2
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
MYSQL_DATABASE: ${DB_DATABASE}
In Docker Run Commands
For docker-run.txt, use the same variable syntax:
docker run -d \
-e MYSQL_ROOT_PASSWORD=${DB_PASSWORD} \
-e MYSQL_USER=${DB_USERNAME} \
-e MYSQL_DATABASE=${DB_DATABASE} \
mariadb:11.2
Default Values
DeployStack supports Docker's default value syntax for environment variables. This provides fallback values when variables are not defined.
Syntax
Use ${VARIABLE:-default} where:
- VARIABLE is your environment variable name
- default is the fallback value
Examples
# docker-compose.yml
services:
web:
image: nginx:alpine
environment:
PORT: ${PORT:-8080}
NODE_ENV: ${NODE_ENV:-development}
# docker-run.txt
docker run -d \
-e PORT=${PORT:-8080} \
-e NODE_ENV=${NODE_ENV:-development} \
nginx:alpine
Environment Variable Processing
When DeployStack processes your repository:
- Variables defined in .deploystack/env are read
- These values replace matching ${VARIABLE} placeholders
- For undefined variables:
If a default value is specified (${VARIABLE:-default}), it's used
Otherwise, an empty string is used
Important Notes
- The env file is optional
- Keep sensitive information out of version control
- Variable names are case-sensitive
- Default values provide fallbacks but don't expose sensitive data
- Environment variables in your Docker configuration must use the ${VARIABLE} syntax
Limitations
- Basic environment variable substitution only
- No variable expansion or shell-style manipulation
- Cannot reference other variables within values
- No built-in encryption for sensitive values