Docs/Deploy/Environment variables

Environment variables

3 min read
On this page

Environment variables hold your app's configuration and secrets: database URLs, API keys, feature flags. Dokwe encrypts every value before storing it and injects the variables into your app at deploy time.

How variables are layered#

Variables live at two levels:

LevelWhere you set itApplies to
ProjectProject → Environment tab, or dokwe envEvery environment, as shared defaults
EnvironmentEnvironment page → Environment Variables tabThat environment only

When a container deploys to an environment, Dokwe merges the two lists. If a key exists at both levels, the environment value wins. Keys you set only at the project level still reach every environment. See Staging and production for how environments fit together.

Native deploys read project-level variables, combined with the env block of your dokwe.yml. The order is: env.defaults from the manifest, then project variables, then environments.<type>.env.defaults. Later sources win. See dokwe.yml reference.

Set variables in the dashboard#

  1. Open the variables tab#

    For shared defaults, open your project and choose the Environment tab. For a per-environment override, open the environment and choose Environment Variables.

  2. Add or edit values#

    In Table mode, select Add variable, enter a key and a value, then select Save changes. To paste many at once, switch to .env editor, paste the contents of a .env file, and save.

  3. Redeploy#

    Saved changes take effect on the next deployment. On the project tab, Dokwe offers Redeploy now right after you save.

Variables prefixed with NEXT_PUBLIC_ are baked into the build. Changing one always needs a redeploy, not just a restart.

Set variables from the CLI#

The CLI manages project-level variables for the linked project. Pass --project (-p) to target a different project.

bash
dokwe env set DATABASE_URL=postgresql://user:pass@host:5432/db
dokwe env get DATABASE_URL
dokwe env remove DATABASE_URL
dokwe env                 # list keys and values

To upload a whole file, use import. It reads .env in the current folder unless you name another file.

bash
dokwe env import .env.production

When you import a file, Dokwe:

  • skips blank lines and lines that start with #
  • skips keys with an empty value
  • removes one pair of matching single or double quotes around a value
  • overwrites keys that already exist and leaves other keys alone

Keys set with dokwe env set or the table must use uppercase letters, numbers, and underscores only.

Edit a local copy#

pull, edit, and push work with a local file at .dokwe/.env.<name>. The name defaults to prod.

bash
dokwe env pull            # write variables to .dokwe/.env.prod
dokwe env edit            # open the file in $EDITOR (or $VISUAL)
dokwe env push            # upload the file to Dokwe

pull writes the file with owner-only permissions (0600). Keep .dokwe/ out of version control.

The --env flag on pull, edit, and push only chooses which local file to use, for example --env staging reads .dokwe/.env.staging. The values still go to the project-level variables. To set a value for a single environment, use the environment page in the dashboard.

Use 1Password references#

Instead of pasting a secret into the local file, write a 1Password secret reference. dokwe env push resolves every op:// reference with the 1Password CLI (op) and uploads the real values.

bash
# .dokwe/.env.prod
DATABASE_URL=postgresql://user:pass@host:5432/mydb
DB_PASSWORD=op://production/postgres/password
API_KEY=op://production/stripe/secret_key
  1. Install and sign in to the 1Password CLI#

    Install op, then run op signin. In CI, set OP_SERVICE_ACCOUNT_TOKEN instead.

  2. Check your setup#

    dokwe vault status confirms that op is installed and signed in, and lists any references it finds in .dokwe/.env.prod.

    bash
    dokwe vault status
  3. Preview the resolved values#

    dokwe vault resolve resolves the references without uploading anything. It prints each value masked to its first and last four characters.

    bash
    dokwe vault resolve
  4. Push#

    bash
    dokwe env push

Dokwe stores the resolved value, not the reference. If you rotate a secret in 1Password, run dokwe env push again and redeploy.

Encryption and access#

Dokwe encrypts each value with AES-256-GCM, using a fresh random IV for every value, before writing it to the database. Keys are stored in plain text so they can be listed.

Values are not write-only. Members and admins can reveal them with Show values in the dashboard or read them with dokwe env get. Viewers see variable names only; the API returns 403 INSUFFICIENT_ROLE if they ask for values.

When changes take effect#

Saving a variable doesn't change the running app. Your app picks up new values on its next deployment. Redeploy from the dashboard, run dokwe deploy, or push a commit.