Read JSON-file into environment variable with Docker Compose

An easy way to do this is to load the JSON file in to a local env var, then use that in your yaml file.

In docker-compose.yml


Load the settings file before invoking docker-compose:

❯ METEOR_SETTINGS=$(cat settings.json) docker-compose up

Not possible without some trickery, depending on the amount of tweakable variables in settings.json:

If it's a lot of settings it's fairly easy to template the docker-compose.yml with a simple shell script that replaces a token in the template with the contents of settings.json, much like in your example. You also want to wrap the docker-compose call in that case. Simplified example:



# replace ##_METEOR_SETTINGS_## with contents of settings.json and output to docker-compose.yml
sed -e 's|##_METEOR_SETTINGS_##|'"$(cat ./settings.json)"'|' \
    "./docker-compose.yml.template" > "./docker-compose.yml"
# wrap docker-compose, passing all arguments
docker-compose "[email protected]"

Put the 2 files into your project root, then chmod +x to make the wrapper executable and call ./ -h.

If it's only a few settings you could handle the templating inside the container when its starting. Simply replace tokens placed in a prepared settings.json with ENV values passed to docker before starting Meteor. This allows you to just use the docker-compose ENV features to configure Meteor.