Skip to content
manual

Environment Variables ​

Baseline applications interact with environment variables across three primary categories:

  • deployment-specific: Variables required to boot a specific instance.
  • container-specific: Configuration for individual containers.
  • public: Non-sensitive defaults shared via version control.

TLDR ​

Use .env for deployment ​

The .env file located alongside your compose.yaml contains the deployment-specific variables required for container bootup. The docker compose command uses these values to replace placeholders in the compose.yaml file.

If you want values to reach the app, pass them through like this:

yaml
services:
    app:
        environment:
            - APP_URL=${APP_URL}

Use .env.example for defaults ​

The .env file inside the deployed container is the renamed .env.example file. It sets default configurations chosen by you for parameters that users do not need to, or should not, overwrite.

Set instance variables in compose.yaml ​

Container-specific variables set configuration values unique to one specific deployed app instance.

Use .env for local settings ​

The .env file in your project root contains deployment-specific variables required to boot your local development environment.

Include this file in version control so the repository is ready for immediate development, but ensure it contains no sensitive information; these values are intended for developer use only.

Its values are used by docker compose to replace placeholders within compose.yaml.

Example: A single MYSQL_PASSWORD definition can be shared across multiple containers.

WARNING

In the development environment, the .env file is also mounted into the app container, meaning variables defined there - such as a MySQL root password - are visible to the baseline app. In production, only the docker compose command reads these values.

To have .env values reach the instance, you must mirror it into the container as shown above

Provide defaults with .env.example ​

The .env.example file in your project root holds public configuration that is safe for version control and public visibility.

When building a docker image for deployment, this file is renamed to .env inside the docker image. Together with the configuration options passed to your Baseline instance, it defines default behaviors for new deployments.

In development, this file is read before .env so this behaviour also work locally. The first value set for a variable will win.

  • Example: Setting APP_NAME ensures your app has a consistent identity upon deployment.
  • Example 2: Defining APP_ROUTING_MODE establishes essential behavior that should not be altered by end-users to ensure application stability.

Define container settings in compose.yaml ​

Container-specific variables set configuration values for a single deployed app instance container.

Example: APP_URL. This should not be defined in .env.example, as different users will deploy the application under unique domains.

Security Risk

Do not use the env_file directive to pass your entire .env file into a container. This exposes sensitive deployment credentials - such as database root passwords - to the application, which should only have access to its specific required configuration.