How can I pass a multi-line variable to a docker container? How can I pass a multi-line variable to a docker container? docker docker

How can I pass a multi-line variable to a docker container?


The YAML syntax is correct. The shell command wasn't:

echo "$KEY"

prints the string with newlines.


Had the same problem a couple of days ago and solved it via:

KEY: "line1\nline2"

Hope that helps in your case as well.


Try using > this solution works pretty well if you need to have a json in your env variables. There are many ways to have a multiline strings in YAML.

version: '2'services:  catalog-api-autoscaling:    image: company.it/project/catalog-api-autoscaling:latest    container_name: api-autoscaling    ports:      - "8083:8083"    environment:        CONFIG_ABC: >          {            "database": {               "catalog": {                   "credentials": {                       "username": "scott",                       "password": "tiger",                       "datbase": "catalog",                       "host": "gn.dmfkd.lan"                    }                }            }          }        CONFIG_DEF: >          {            "urlRegex": "/.*",            "script": {              "scriptPath": "example-python-app.py"            },            "runtime": "python27",            "threadsafe": true,          }