I have a simple PHP app which keeps its configuration in a JSON file which is loaded into the app using the Noodlehouse\Config configuration loader. Now I would like to share this app also as a Docker image, but I don’t want the configuration to be embedded in the image. As I have read - the preferred Docker-way would be passing these configuration variables as environment variables.
What is the best way to do this? Do I have to rewrite the configuration loading part in my app so it’s able to load config variables from the environment or are there any nice tricks so I don’t have to overcomplicate the configuration loading process in my app?
I don’t want to have the config loaded only via env variables because some instances of this app are being used on a shared server.
I don’t want my app to be “Docker-only” - the docker image is just in case as a way to run the app.
My example configuration for this app:
{
"provider": {
"api": {
"hash": "9061b79dc966a3fe0831dec",
"login": "johndoe",
"pass": "7MAW8S!Dc2aT6Lg*i&rkpF5k!P"
}
},
"mailer": {
"host": "smtp.contoso.com",
"port": 587,
"user": "noreply@contoso.com",
"password": "3k@2veWF9i&SKESjv9g83!o*v@",
}
}
The way I’m loading the configuration:
use Noodlehaus\Config;
$config = Config::load('config/config.json');
echo $config->get('provider.api.hash');
echo $config->get('provider.api.login');
echo $config->get('provider.api.pass');
Is there a nice way of doing this? Maybe I should use another configuration loader?