compose-go
compose-go copied to clipboard
Compose handles key-only .env file differently than Docker and Docker-Compose
Hi! I have been testing docker compose
with environment variables and the result differs from Docker and Docker-Compose.
Test
Define a .env
file with the following:
ENV_A
ENV_B=
ENV_C=env_c
And a docker-compose.yml
file:
services:
alpine:
image: alpine
env_file: .env
Docker
$ docker run --rm --env-file=.env alpine env
ENV_B=
ENV_C=env_c
Here ENV_A
has not been set and ENV_B
is set with an empty value.
Docker-Compose
$ docker-compose run --rm alpine env
ENV_B=
ENV_C=env_c
With Docker-Compose, we get the same outcome as Docker
Compose
$ docker compose run --rm alpine env
ENV_C=env_c
ENV_A=ENV_B=
Here's where the outcome is quite unexpected: ENV_A
is set with the value ENV_B=
.
Compose seems to have a problem with key-only items in .env
file.
Just realised that this issue could be in https://github.com/docker/compose? or https://github.com/compose-spec/godotenv (couldn't create an issue)?
Created this PR https://github.com/compose-spec/godotenv/pull/12 :)
This issue (and many others) should be fixed now. Thanks for reporting and the PR(s) to fix it!