Passing Custom Environment Variables to Docker Container
fzngagan asked if it’s possible to pass custom environment variables to a Docker container via a YAML file. They initially tried adding export VAR=VALUE to the custom commands section and VARIABLE: VALUE to the env section, but encountered issues.
Justin suggested using the env: section of the container definition, which fzngagan initially had trouble with due to a multiline value. However, fzngagan eventually got it working by removing the multiline value.
To use multiline values, fzngagan found that wrapping the key in single quotes and adding an extra \ to each \n was necessary. However, featheredtoast suggested a cleaner approach using YAML’s multiline support with the | character.
fzngagan clarified that the key can be pasted as-is with no edits, aside from prefixed spaces. This approach was confirmed by featheredtoast.
In summary, to pass custom environment variables to a Docker container, use the env: section of the container definition, and for multiline values, use YAML’s multiline support with the | character.
That gives me an error related to docker. That would be very intuitive if it worked like that. Or I’m crazy. I think there’s a rule to accept custom vars starting with DISCOURSE_.
So, I was crazy. This works fine. The issue was due to a multiline value. I removed it and the build suceeded. But the question is, how to use multiline values?
Yuhoo, I was able to make it work. The issue was that I was using a RSA Private key as an environment variable. This is what needs to be done to make that work.
wrap your key in single quotes '' and add an extra \ with all the \n appearing in the key. i.e. \n would be come \\n.