18

Im using docker-compose, and Im using env file with my local variables. I need to pass array variable. I have tried:

TAGS="12345","67890"

or

TAGS=["12345","67890"]

or

TAGS=("12345" "67890")

Im getting always error:

List(WrongType(STRING,Set(LIST, OBJECT),Some(ConfigValueLocation(file:/src/target/scala-2.12/classes/application.conf,86))

Any idea how to achieve this ?

1
  • 3
    There is no array type support for docker-compose.yml, you might want to add it as a comma-separated-string, and explode it to different elements as a comma (using a bash script). Commented Apr 18, 2017 at 12:12

3 Answers 3

19

As Confidence mentioned above, write a comma separated string:

TAGS=12345,67890

Then in your application (Python for instance):

os.getenv('TAGS').split(',')
Sign up to request clarification or add additional context in comments.

Comments

0

Using Spring Boot Framework, this can be achieved with the SPRING_APPLICATION_JSON property:

services:
  my-app:
    image: my-app:latest
    environment:
      - SPRING_APPLICATION_JSON={
          "TAGS":[12345,67890]
        }
    ports:
      - "8080:8080"

2 Comments

dont you needs some thing like - | or - > to make the multiline work?
No, i wondered myself too, but this works as is in my docker-compose.yml. Everything else didn't work, like beginning ' or ". I have this currently running. (With subobjects in the array).
0

If you finally use your ENV variable in a bash script you may try Command Substitution principal

.env file:

ARRAY_BODY_EXPR="cat dog mouse frog"

In Dockerfile:

SHELL ["/bin/bash", "-c"]
RUN myArray=( $(echo ${ARRAY_BODY_EXPR}) );\
  for str in ${myArray[@]}; do \
    # do something with str
  done

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.