compose-spec / compose-go

Reference library for parsing and loading Compose YAML files

Home Page:https://compose-spec.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compose handles key-only .env file differently than Docker and Docker-Compose

flemay opened this issue · comments

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)?

This issue (and many others) should be fixed now. Thanks for reporting and the PR(s) to fix it!