docker: poorly formatted environment: variable contains whitespaces docker: poorly formatted environment: variable contains whitespaces docker docker

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:

  1. >.env - make .env to be an empty file
  2. for var in $(compgen -v | grep -Ev '^(BASH)'); do - iterate over env keys
  3. var_fixed=$(printf "%s" "${!var}" | tr -d '\n' ) - remove new-lines from key value
  4. echo "$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