Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable name may not contain whitespace #6838

Closed
alfredopalhares opened this issue Aug 7, 2019 · 6 comments · Fixed by #7150
Closed

Variable name may not contain whitespace #6838

alfredopalhares opened this issue Aug 7, 2019 · 6 comments · Fixed by #7150

Comments

@alfredopalhares
Copy link

Description of the issue

Docker compose does not recnognize a valid yaml file, even when validated with a yamlint.org.

Context information (for bug reports)

Output of docker-compose version

-> % docker-compose version
docker-compose version 1.24.1, build unknown
docker-py version: 4.0.2
CPython version: 3.7.4
OpenSSL version: OpenSSL 1.1.1c  28 May 2019

Output of docker version

Client:
 Version:           19.03.1-ce
 API version:       1.40
 Go version:        go1.12.7
 Git commit:        74b1e89e8a
 Built:             Sat Jul 27 21:08:50 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          19.03.1-ce
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.7
  Git commit:       74b1e89e8a
  Built:            Sat Jul 27 21:08:28 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.7.m
  GitCommit:        85f6aa58b8a3170aec9824568f7a31832878b603.m
 runc:
  Version:          1.0.0-rc8
  GitCommit:        425e105d5a03fabd737a126ad93d62a9eeede87f
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Output of docker-compose config
(Make sure to add the relevant -f and other flags)

ERROR: In file /home/masterkorp/Documents/prozis/repos/prozis-events/events-backend/docker/env/its.yaml: environment variable name 'host: hostname' may not contains whitespace.

Steps to reproduce the issue

Just tun any docker command

Observed result

Docker compose fails to run

Expected result

Should run

Additional information

OS Arch Linux Updated, but it happens accroos all OS.

@ulyssessouza
Copy link
Collaborator

@alfredopalhares Could you please, provide the YAML file?

@tjb-wiley
Copy link

tjb-wiley commented Aug 9, 2019

i experienced this same issue, and after spending most of the afternoon, it looks like like maybe something changed with the way docker-compose processes .env files. and the only reason i hit this is because i upgraded docker on my mac laptop from docker for mac to docker desktop.

current behavior on macos

docker version
Client: Docker Engine - Community
 Version:           19.03.1
 API version:       1.40
 Go version:        go1.12.5
 Git commit:        74b1e89
 Built:             Thu Jul 25 21:18:17 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

With a .env file that looks like this:

cat .env
# POSTGRES
export POSTGRES_USER=foo
export POSTGRES_DB=secret

and a docker-compose.yaml that looks like this:

version: '3'
services:
  db:
    image: postgres:latest
    ports:
      - "5432:5432"
    volumes:
      -  ./data/postgresql:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: ${POSTRES_USER:-foo}
      POSTGRES_DB: ${POSTGRES_DB:-foo}

[ ... ]

run any docker-compose command will result in this error:

docker-compose ps
ERROR: In file ./.env: environment variable name 'export POSTGRES_USER' may not contains whitespace.

If I remove the export from the .env file and re-run the above, everything works.

Current behavior on Linux (ubuntu 19.0.4)

Running the same commands as above, with the same setup as above, the same command works as expected.

That said, the docker.io package on my ubuntu installation is 18.09.7.

I should point out that I figured the above out in most part due to this blog post:
https://vsupalov.com/docker-arg-env-variable-guide/

@tjb-wiley
Copy link

Looks like this behavior changed with this commit:
9d2508c

@markeissler
Copy link

Anything in the .env file will be loaded and exposed within the environment when you run docker-compose. There's never been a need to export those vars.

With that said, it's often convenient to export variables here for other things. For instance, I'll export vars for injection into my shell via .envrc and direnv. The .envrc file is checked in, the .env file is not. So the .env file has been a great place for me to define and export my GIT_* vars (GIT_AUTHOR_EMAIL, GIT_COMMITTER_EMAIL, etc.) which I need in my local terminal shell but not within the docker-compose environment.

The commit indicated by @tjb-wiley breaks my workflow. I think docker-compose should ignore any line that starts with export. In the meantime, I created an .env.local file that I source in my .envrc and removed my export lines from .env.

@Quintasan
Copy link

Can't we just have docker-compose treat lines beginning as normal lines? So
export VAR=foo behaves the same as VAR=foo?

@tjb-wiley
Copy link

Looks like this is a known issue, going back to Feb of this year:
#6511

adityapahuja added a commit to alphagov/passport-verify-stub-relying-party that referenced this issue Mar 20, 2020
This change fix the following error message by removing export from local-vsp-only.env. Please see the issue (docker/compose#6838). According to Docker documentation, there is no need to have export in the environment file (Source: https://docs.docker.com/compose/compose-file/#env_file#env_file).

ERROR: In file /tmp/build/a94a8fe5/passport-verify-stub/local-vsp-only.env: environment variable name 'export SERVICE_ENTITY_IDS' may not contains whitespace.

Author: @adityapahuja
adityapahuja added a commit to alphagov/passport-verify-stub-relying-party that referenced this issue Mar 20, 2020
This change fixes the following error message by removing export from local-vsp-only.env. Please see the issue (docker/compose#6838). According to Docker documentation, there is no need to have export in the environment file (Source: https://docs.docker.com/compose/compose-file/#env_file#env_file).

ERROR: In file /tmp/build/a94a8fe5/passport-verify-stub/local-vsp-only.env: environment variable name 'export SERVICE_ENTITY_IDS' may not contains whitespace.

Author: @adityapahuja
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants