compose: [BUG] unexpected character "-" in variable name since v2.29.3
Description
Environment variables defined via an env_file that have “-” characters in their name get refused after updating docker-compose from v2.29.2 to v2.29.3
Steps To Reproduce
services:
env_runner:
image: alpine
command: env
env_file:
- ./myenv.env
myenv.env
foo-bar=test
Expected behaviour (v2.29.2)
$ docker compose up
[+] Running 1/1
✔ Container env_runner-1 Created
Attaching to env_runner-1
[…]
env_runner-1 | foo-bar=test
env_runner-1 exited with code 0
Actual behaviour (v2.29.3)
$ docker compose up
failed to read myenv.env: line 1: unexpected character "-" in variable name "foo-bar=test"
Compose Version
Docker Compose version 2.29.3
Docker Environment
Client:
Version: 27.2.0
API version: 1.47
Go version: go1.23.0
Git commit: 3ab4256958
Built: Thu Aug 29 16:44:26 2024
OS/Arch: linux/amd64
Context: default
Server:
Engine:
Version: 27.2.0
API version: 1.47 (minimum version 1.24)
Go version: go1.23.0
Git commit: 3ab5c7d003
Built: Thu Aug 29 16:44:26 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.7.22
GitCommit: 7f7fdf5fed64eb6a7caf99b3e12efcf9d60e311c.m
runc:
Version: 1.1.14
GitCommit:
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 18 (10 by maintainers)
When will the fix be published? I’ve tested docker compose
v2.29.7and I still get the same error.I’m confused, I thought earlier comments said this was fixed, it’s been working before the update.
see https://github.com/compose-spec/compose-go/issues/663
For those affected by this issue:
A possible workaround is to remove the respective variables from the .env file and instead apply them via the “environment”
character
-is not supported in variable names, as this collides with default value syntax (${FOO-default_value}) and makes parsing non-deterministic