Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash associative array in .yml definition #3726

Closed
zrml opened this issue Jul 12, 2016 · 5 comments
Closed

bash associative array in .yml definition #3726

zrml opened this issue Jul 12, 2016 · 5 comments

Comments

@zrml
Copy link

zrml commented Jul 12, 2016

it might be totally my fault,
but a couple of fairly obvious syntax to retrieve a passed-in array is failing with an "Invalid interpolation format" error.

In the doc it says that arrays are supported. In my case, being tricky, I need to make use of the associative array (bash > v4)

Any hope for me?
thank you

@aanand
Copy link

aanand commented Jul 12, 2016

Arrays are not supported. Which document are you looking at?

@zrml
Copy link
Author

zrml commented Jul 12, 2016

https://docs.docker.com/compose/compose-file/

search for "array"

Thanks @aanand
that's a great shame and forces me in a very uncomfortable position in my company...

@zrml
Copy link
Author

zrml commented Jul 12, 2016

thinking about it: you have access to the shell environment so you can see it all, I guess:
Can I ask for an enhancement request?

@aanand
Copy link

aanand commented Jul 12, 2016

OK, I think we're talking about different things. What that document states is that YAML values for build.args, environment and labels can be either arrays or dictionaries. That means that you can specify a set of e.g. environment variables for the container in two ways:

# as an array
environment:
  - FOO=hello
  - BAR=world

# as a dictionary
environment:
  FOO: hello
  BAR: world

Environment variable interpolation, however, necessarily deals with strings, because environment variables can only be strings. This is true of all command-line tools, not just Compose. For example, env can't see Bash variables that aren't strings:

$ FOO=hello
$ export FOO
$ env | grep FOO
FOO=hello
$ FOO=(1 2 3)
$ export FOO
$ env | grep FOO
(no output)

It's therefore not possible for Compose to understand Bash associative arrays.

@zrml
Copy link
Author

zrml commented Jul 12, 2016

  1. OK, got the interpretation of array in the doc: it refers to the YML definition. Thanks
  2. you stand correct that arrays (even normal integer based, like your example) are not exported.
    we'll have to wait for bash v.5 :-)
    thank you @aanand

@zrml zrml closed this as completed Jul 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants