{"action":"created","issue":{"url":"https://api.github.com/repos/docker/compose/issues/1377","labels_url":"https://api.github.com/repos/docker/compose/issues/1377/labels{/name}","comments_url":"https://api.github.com/repos/docker/compose/issues/1377/comments","events_url":"https://api.github.com/repos/docker/compose/issues/1377/events","html_url":"https://github.com/docker/compose/issues/1377","id":72233302,"number":1377,"title":"Interpolate environment variables in docker-compose.yml","user":{"login":"aanand","id":1062,"avatar_url":"https://avatars.githubusercontent.com/u/1062?v=3","gravatar_id":"","url":"https://api.github.com/users/aanand","html_url":"https://github.com/aanand","followers_url":"https://api.github.com/users/aanand/followers","following_url":"https://api.github.com/users/aanand/following{/other_user}","gists_url":"https://api.github.com/users/aanand/gists{/gist_id}","starred_url":"https://api.github.com/users/aanand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aanand/subscriptions","organizations_url":"https://api.github.com/users/aanand/orgs","repos_url":"https://api.github.com/users/aanand/repos","events_url":"https://api.github.com/users/aanand/events{/privacy}","received_events_url":"https://api.github.com/users/aanand/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":37,"created_at":"2015-04-30T17:53:16Z","updated_at":"2015-05-26T22:40:49Z","closed_at":null,"body":"(I'm creating a fresh issue for this as the [old one](https://github.com/docker/compose/issues/495) has accumulated rather a lot of baggage.)\r\n\r\nIt should be possible to pass in environment variables to the value of any* configuration entry in `docker-compose.yml`. A lot of people want to do it, it's good for portability and I'm satisfied it's not going to cause chaos.\r\n\r\nI have some reckons.\r\n\r\n### Required variables and optional defaults\r\n\r\nIt's useful to be able to specify that a variable that *must* be present in the environment, i.e. that Compose will refuse to run if it isn't. However, this will be a pain when you've got lots of them, so it should either be something you explicitly enable, or it should be possible to specify a default value.\r\n\r\nThe MVP implementation does not need to have either feature, but there should be a clear path to implementing both in a backwards-compatible way.\r\n\r\n### Syntax\r\n\r\nThere's a strong case for implementing an established standard, as long as it's not heavyweight - our requirements for functionality are minimal.\r\n\r\n-   [POSIX parameter expansion](http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02) is OK. It has a few too many features, but we could implement a subset of them:\r\n\r\n    - `${VARIABLE}` - outputs empty string if `VARIABLE` is unset\r\n    - `${VARIABLE-default}` - outputs `default` if `VARIABLE` is unset\r\n    - `${VARIABLE?}` - errors out if `VARIABLE` is unset\r\n\r\n    https://github.com/docker/compose/pull/845 implemented a Bash-style `${VARIABLE:default}` syntax, which is similar to POSIX parameter expansion but slightly different.\r\n\r\n-   [Python's format syntax](https://docs.python.org/2/library/string.html#formatstrings) would be trivial to implement, but is tied to the Python language, and has rather too many features.\r\n\r\n### Implementation\r\n\r\nSo far, https://github.com/docker/compose/pull/845 is the closest we've got, but I'm fundamentally wary of an implementation that relies on regular expressions. Templating is a non-trivial job, and people are going to put all kinds of broken stuff in, so we need something that's robust, strict and errors out with helpful messages. Two important requirements:\r\n\r\n- If someone puts in something malformed, Compose will not run.\r\n- It is possible to escape any of the special characters used in the template syntax.\r\n\r\nThere may well be good Python implementations of Bash-like variable interpolation out there already - if not, creating something standalone would be far preferable to bloating the Compose codebase.\r\n\r\n\\*Actually, are there any configuration keys for which we *shouldn't* allow interpolation?"},"comment":{"url":"https://api.github.com/repos/docker/compose/issues/comments/105689673","html_url":"https://github.com/docker/compose/issues/1377#issuecomment-105689673","issue_url":"https://api.github.com/repos/docker/compose/issues/1377","id":105689673,"user":{"login":"kevana","id":981551,"avatar_url":"https://avatars.githubusercontent.com/u/981551?v=3","gravatar_id":"","url":"https://api.github.com/users/kevana","html_url":"https://github.com/kevana","followers_url":"https://api.github.com/users/kevana/followers","following_url":"https://api.github.com/users/kevana/following{/other_user}","gists_url":"https://api.github.com/users/kevana/gists{/gist_id}","starred_url":"https://api.github.com/users/kevana/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevana/subscriptions","organizations_url":"https://api.github.com/users/kevana/orgs","repos_url":"https://api.github.com/users/kevana/repos","events_url":"https://api.github.com/users/kevana/events{/privacy}","received_events_url":"https://api.github.com/users/kevana/received_events","type":"User","site_admin":false},"created_at":"2015-05-26T22:40:49Z","updated_at":"2015-05-26T22:40:49Z","body":"+1 for reading the file from stdin. I have no problem with using an external template solution but not having intermediate files around would be nice.\r\n"}}