A Rust library to easily access Docker secrets.
Docker secrets are mounted into the container at /run/secrets. This library provides a simple interface to read them.
Add this to your Cargo.toml:
[dependencies]
docker_secrets = "0.2.0"Returns a list of secret names found in /run/secrets.
use docker_secrets::get_list;
fn main() {
match get_list() {
Ok(secrets) => {
for secret in secrets {
println!("Found secret: {}", secret);
}
}
Err(e) => eprintln!("Error listing secrets: {}", e),
}
}Reads the content of a specific secret.
use docker_secrets::get;
fn main() {
match get("my_secret") {
Ok(secret_value) => println!("Secret value: {}", secret_value),
Err(e) => eprintln!("Error reading secret: {}", e),
}
}By default, the library looks for secrets in /run/secrets. You can override this path by setting the DOCKER_SECRETS_DIR environment variable. This is useful for local development and testing.
export DOCKER_SECRETS_DIR=./my_local_secrets
cargo runThis project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.