A simple PHP library to read docker secrets from a Swarm cluster.
composer require sadok-f/docker-secrets
$dockerSecrets = new DockerSecrets\Reader\SecretsReader();
$allSecrets = $dockerSecrets->readAll();
return:
Array
(
[my_secret_data_1] => testSecretDataContent1
[my_secret_data_2] => testSecretDataContent2
)
$dockerSecrets = new DockerSecrets\Reader\SecretsReader();
$dockerSecrets->read('my_secret');
The default location for secrets folder is to /run/secrets/
in Linux containers.
if you're using Docker 17.06 and higher with custom location you can use the library like this example:
$dockerSecrets = new DockerSecrets\Reader\SecretsReader('/var/myCustomLocation');
$dockerSecrets->read('my_secret');
$dockerSecrets = new DockerSecrets\Reader\SecretsReader('C:\ProgramData\Docker\secrets');
$dockerSecrets->read('my_secret');
./vendor/bin/phpunit