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:

bash
your-repository/
├── .deploystack/
   ├── env
└── README.md

Your env file should follow the standard environment file format:

bash
# .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:

yaml
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:

bash
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

yaml
# docker-compose.yml
services:
  web:
    image: nginx:alpine
    environment:
      PORT: ${PORT:-8080}
      NODE_ENV: ${NODE_ENV:-development}
bash
# 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:

  1. Variables defined in .deploystack/env are read
  2. These values replace matching ${VARIABLE} placeholders
  3. 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