compose: env_file parsing does not handle unquoted whitespace cleanly
Description
Using an env_file with unescaped whitespace keys breaks compose. Additionally, the error message does not really tell the user which file / line is in issue, or that it’s an env_file issue at all
Steps to reproduce the issue:
docker-compose.yml:
services:
alpine:
image: alpine
env_file: variables.env
variables.env:
VAR=foo bar baz
run docker compose config
Describe the results you received:
% docker compose config
key cannot contain a space
Because the error message does not mention the env file, with a large Yaml config it’s very unclear where the problem may lie
Describe the results you expected:
This works with v1:
% docker-compose config
services:
alpine:
environment:
VAR: foo bar baz
image: alpine
version: '3.9'
If the whitespace in the env file is valid, compose should behave the same as v1.
If it’s not possible to change the env parsing at this stage, there needs to be an error message that makes it clear what has happened. Ideally we’d point to the line number in the .env file, but if that’s not technically possible we could point to the line number of the env_file: in the Yaml
Output of docker compose version
:
Docker Compose version v2.0.0
Output of docker info
:
Client:
Context: default
Debug Mode: false
Plugins:
buildx: Build with BuildKit (Docker Inc., v0.6.3)
compose: Docker Compose (Docker Inc., v2.0.0)
scan: Docker Scan (Docker Inc., v0.8.0)
Server:
Containers: 42
Running: 16
Paused: 0
Stopped: 26
Images: 73
Server Version: 20.10.8
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: e25210fe30a0a703442421b0f60afac609f950a3
runc version: v1.0.1-0-g4144b63
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 5.10.47-linuxkit
Operating System: Docker Desktop
OSType: linux
Architecture: aarch64
CPUs: 4
Total Memory: 11.68GiB
Name: docker-desktop
ID: 552J:DQQK:IROJ:YEMG:H5VB:EUS5:5MEX:VKDI:CQAG:KHXR:CLTY:TJY5
Docker Root Dir: /var/lib/docker
Debug Mode: false
HTTP Proxy: http.docker.internal:3128
HTTPS Proxy: http.docker.internal:3128
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 12
- Comments: 19 (1 by maintainers)
Links to this issue
Commits related to this issue
- Quote environment values with spaces for compatibility with docker2 See https://github.com/docker/compose/issues/8763 — committed to CodingPirates/forenings_medlemmer by jarl-dk 3 years ago
- Quote environment values with spaces for compatibility with docker2 See https://github.com/docker/compose/issues/8763 — committed to CodingPirates/forenings_medlemmer by jarl-dk 3 years ago
- Quote environment values with spaces for compatibility with docker2 See https://github.com/docker/compose/issues/8763 — committed to CodingPirates/forenings_medlemmer by jarl-dk 3 years ago
- Quote environment values with spaces for compatibility with docker2 See https://github.com/docker/compose/issues/8763 — committed to CodingPirates/forenings_medlemmer by jarl-dk 3 years ago
- Quote environment values with spaces for compatibility with docker2 (#699) See https://github.com/docker/compose/issues/8763 Co-authored-by: Kristoffer Rath Hansen <kristoffer@rathhansen.com> — committed to CodingPirates/forenings_medlemmer by jarl-dk 2 years ago
We will have a look at the parser to check how complicated that would be without breaking the multiline feature. Since that’s a forked code that’s not that clear for now. I recommend to fix the env files for now. But we will have a look at this to try to fix that.
Only thing I’ve been able to do is single quote my
.env
files. it’s compatible both ways then.Only works in v1
Works in v1 and v2
This isn’t a workaround so much as being forced to adapt my
.env
file and anything else I use that interacts with the.env
file.@Shikachuu yeah I appreciate it may not be possible to change the parsing, but the user experience of the error message could be improved
because it doesn’t mention env at all, in the real world case we spent a long time trying to see what was wrong with our Yaml!
maybe when this error occurs we could add a line like this: