| Crates.io | docker-env |
| lib.rs | docker-env |
| version | 0.1.0 |
| created_at | 2025-04-14 15:29:45.858668+00 |
| updated_at | 2025-04-14 15:29:45.858668+00 |
| description | Typed environment variable and secret handling for Dockerised Rust apps. |
| homepage | |
| repository | https://github.com/alexjthomson/docker-env |
| max_upload_size | |
| id | 1633001 |
| size | 29,039 |
A small Rust utility crate for reading environment variables and Docker-style secrets in containerised applications.
This library is designed for applications running in Docker or Kubernetes environments where secrets may be injected either as environment variables or mounted files.
_FILE suffix (e.g.,
DATABASE_PASSWORD_FILE).tracing).Add to your Cargo.toml:
[dependencies]
docker-env = "0.1"
use docker_env::{get_env, get_env_or, get_env_or_panic};
// Read a value as a secret (from a file path in ENV)
let password: String = get_env("DATABASE_PASSWORD", true).unwrap();
// Read with a fallback default
let port: u16 = get_env_or("PORT", 8080, false);
// Panic if missing (e.g., required configuration)
let api_key: String = get_env_or_panic("API_KEY", false);
If a variable is marked with has_secret = true, docker-env will first attempt to read its corresponding secret file.
For example, if your app expects:
DATABASE_PASSWORD_FILE=/run/secrets/db_password
Then calling:
get_env::<String>("DATABASE_PASSWORD", true);
will load the contents of /run/secrets/db_password.