Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read JSON-file into environment variable with Docker Compose

I've dockerized a Meteor-app with Meteord, and that works fine, my problem is that I want to pass some settings to the app.

Meteord does not start the app with a settings-file as one would usually do to give settings to an app (meteor --settings file.json). This is also possible to do with an environement variable called METEOR_SETTINGS.

As I want the webapp to run with other services, I'm using Docker Compose.

I have my settings.json-file that I want to be read in as a environment variable, so something like:

  environment:
   - METEOR_SETTINGS=$cat(settings.json)

This doesn't work though.

How can I make Docker compose dynamically create this environment variable based on a JSON-file?

like image 282
Esso Avatar asked Apr 17 '16 19:04

Esso


1 Answers

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

environment:
  METEOR_SETTINGS: ${METEOR_SETTINGS}

Load the settings file before invoking docker-compose:

❯ METEOR_SETTINGS=$(cat settings.json) docker-compose up
like image 69
Kevin Newman Avatar answered Sep 23 '22 00:09

Kevin Newman