Vivarium
Reference

Environment Variables

All environment variables generated by Vivarium

Vivarium generates two categories of env files:

  1. Compose env file -- written to ~/.local/share/vivarium/<name>/.env. Used by Docker Compose for variable interpolation. Not intended for your application code.
  2. Package env files -- written to paths defined by envFile in each package config. These are the .env files your application actually reads.

Package env files are only written for packages that have envFile set in their config.

Only packages named backend and frontend receive convention-based environment variables. Any other package name (e.g., worker) only gets the vars you explicitly define in that package's env field.


Compose Env File

These variables are written to ~/.local/share/vivarium/<name>/.env and used exclusively by Docker Compose for container configuration and port binding. They are not written to your project directories.

VariableConditionDescription
COMPOSE_PROJECT_NAMEAlwaysUnique project name for Docker Compose namespace
POSTGRES_USERpostgres configuredDatabase user
POSTGRES_PASSWORDpostgres configuredDatabase password
POSTGRES_DBpostgres configuredDatabase name
POSTGRES_PORTpostgres configuredHost port for Postgres
REDIS_PORTredis configuredHost port for Redis
S3_ACCESS_KEYs3 configuredMinIO access key
S3_SECRET_KEYs3 configuredMinIO secret key
S3_PORTs3 configuredHost port for MinIO API
S3_CONSOLE_PORTs3 configuredHost port for MinIO console

Backend Package Env File

Generated when the package key is backend. Written to the path defined by envFile.

Always present

VariableExampleDescription
API_LISTEN_PORT4001Port the backend server should bind to
API_URLhttp://localhost:4001Full URL of the backend API

With frontend package present

VariableExampleDescription
FRONTEND_URLhttp://localhost:4000URL of the frontend package

With postgres configured

VariableExampleDescription
DATABASE_URLpostgresql://app:secret@localhost:5432/myappFull Postgres connection string

With redis configured

VariableExampleDescription
REDIS_ENABLEDtrueSignals that Redis is available
REDIS_URLredis://localhost:6380Full Redis connection URL

With s3 configured

VariableExampleDescription
AWS_S3_REGIONus-east-1Region (always us-east-1 for MinIO compatibility)
AWS_S3_ACCESS_KEY_IDminioadminS3 access key
AWS_S3_SECRET_ACCESS_KEYminioadminS3 secret key
AWS_S3_ENDPOINThttp://localhost:9000MinIO API endpoint
AWS_S3_BUCKET_NAMEassetsFirst bucket name from config
AWS_S3_TEMP_BUCKET_NAMEtempSecond bucket name (only if two or more buckets are configured)

Frontend Package Env File

Generated when the package key is frontend. Written to the path defined by envFile.

The variable prefix depends on the framework field in the package config.

Framework Prefix

framework valuePrefix
nextjs (default)NEXT_PUBLIC_
viteVITE_

In the tables below, {PREFIX} refers to whichever prefix applies.

Always present

VariableExampleDescription
PORT4000Port the frontend server should bind to
{PREFIX}FRONTEND_URLhttp://localhost:4000Full URL of the frontend

With backend package present

VariableExampleDescription
{PREFIX}API_URLhttp://localhost:4001URL of the backend API

With s3 configured

VariableExampleDescription
{PREFIX}ASSET_SRChttp://localhost:9000MinIO API endpoint, for serving assets

Custom Env Overrides

The env field in any PackageConfig lets you add or override variables:

{
  "packages": {
    "backend": {
      "envFile": "backend/.env",
      "env": {
        "LOG_LEVEL": "debug",
        "DATABASE_URL": "postgresql://other:pass@localhost:5432/override"
      }
    }
  }
}

Custom env values are merged last via Object.assign. They always win over convention-generated variables. In the example above, the custom DATABASE_URL replaces the one Vivarium would normally derive from the postgres service config.

Any key-value pair you add is included as-is in the output file.


Override Precedence

convention-generated vars  <  custom env overrides

Convention vars are computed first. Custom env entries are applied on top via Object.assign. There is no further merging -- it is a flat override.

On this page