docker: poorly formatted environment: variable contains whitespaces
The problem occur because the way docker parses this file it does not accept multi-line string and whitespaces in the key names. See relevant issue.
Workaround. Strip all line-endings from multi-line variables:
>.envfor var in $(compgen -v | grep -Ev '^(BASH)'); do var_fixed=$(printf "%s" "${!var}" | tr -d '\n' ) echo "$var=${var_fixed}" >>.envdone
Each line explained:
>.env
- make.env
to be an empty filefor var in $(compgen -v | grep -Ev '^(BASH)'); do
- iterate over env keysvar_fixed=$(printf "%s" "${!var}" | tr -d '\n' )
- remove new-lines from key valueecho "$var=${var_fixed}" >>.env
- write key=value pair to.env
file
For me this was caused by having export
in the .env
file:
export ENDPOINT=https://endpoint.io
Instead do
ENDPOINT=https://endpoint.io
See also: https://github.com/docker/for-linux/issues/701#issuecomment-506884219