Skip to content

Environment & Secrets Management

How environment variables and secrets flow through Dockrion — from .env files to your running agent.

When you run dockrion run or dockrion build, the SDK automatically looks for env files:

FileFormatChecked
.envKEY=value (dotenv)Always
env.yaml / env.ymlKEY: value (YAML)Always
--env-file <path>Either formatWhen flag is provided
1. Shell environment (os.environ) ← always wins
2. --env-file flag
3. .env file
4. env.yaml / env.yml

Later sources do not override earlier ones.

.env
OPENAI_API_KEY=sk-dev-key-...
DOCKRION_API_KEY=my-dev-key
DATABASE_URL=postgresql://localhost/mydb
secrets:
required:
- name: OPENAI_API_KEY
description: "OpenAI API key"
- name: DOCKRION_API_KEY
description: "API key for callers"
optional:
- name: DATABASE_URL
default: "sqlite:///local.db"
Terminal window
# Auto-detected .env
dockrion run
# Explicit env file
dockrion run --env-file .env.staging

All declared secrets must be resolvable from the environment. Missing required secrets raise MissingSecretError.

By default, required secrets must be available for validation. But in CI/CD where production secrets aren’t available locally:

Terminal window
dockrion build --allow-missing-secrets

This skips secret validation during build. Secrets are expected to be provided at runtime (via docker run -e or orchestrator env injection).

Terminal window
dockrion build --env-file .env.ci --allow-missing-secrets

The env file is used for secret validation only — secrets are not baked into the Docker image.

Dockfile secrets.required Shell env + .env files
│ │
▼ ▼
resolve_secrets(secrets_config, loaded_env, shell_env)
For each required secret:
├── Found in shell env → use it
├── Found in loaded env files → use it
├── Has default → use default
└── Missing → MissingSecretError (if strict)
For each optional secret:
├── Found → use it
├── Has default → use default
└── Missing → skip (no error)
Terminal window
dockrion run --verbose

With --verbose, the CLI shows an environment summary:

Environment Summary:
Resolved: OPENAI_API_KEY, DOCKRION_API_KEY
Missing (optional): LANGFUSE_PUBLIC_KEY
Source: .env (2 vars), shell (1 var)
ProblemCauseFix
MissingSecretError: OPENAI_API_KEYNot in shell or .envAdd to .env or export it
Secret resolved but wrong valueShell env overriding .envCheck echo $VAR_NAME in your shell
.env not foundWrong directoryRun from the project root or use --env-file
YAML env file ignoredWrong filenameMust be env.yaml or env.yml (not environment.yaml)
Terminal window
docker run -d \
-e OPENAI_API_KEY=sk-... \
-e DOCKRION_API_KEY=my-key \
-p 8080:8080 \
dockrion/my-agent:v1.0
services:
agent:
image: dockrion/my-agent:v1.0
ports:
- "8080:8080"
env_file:
- .env.production
environment:
- OPENAI_API_KEY=${OPENAI_API_KEY}
Terminal window
dockrion add secrets OPENAI_API_KEY,DATABASE_URL
dockrion add secrets LANGFUSE_PUBLIC_KEY --optional

Source: load_env_files(), resolve_secrets(), validate_secrets() in packages/common-py/dockrion_common/env_utils.py


Previous: 5.1 Installation | Next: 5.3 Adding Auth →