Skip to content

[BUG] dashes not supported in environment variable names in .env files #12302

@vvuk

Description

@vvuk

Description

This was seemingly fixed in #9570 last year, and looking at the code it doesn't look like the code regressed, but I can't seem to include environment variables with a - in them via env_file in a compose file.

Steps To Reproduce

foo.env contains (hello ASP.NET config env vars):

services__storage-service__http__0=http://storage:2227

docker-compose.yaml contains:

services:
  storage:
    image: ..
    env_file: foo.env

trying to do up errors out with:

failed to read ...foo.env: line 1: unexpected character "-" in variable name "services__storage-service__http__0=http://storage:2227"

(I'm also a little confused why it prints the entire line as "variable name" but I think that's just a printing issue?)

I can define variables with a - in them fine directly in environment: entries in the compose file.

Compose Version

Docker Compose version v2.29.7, Ubuntu 22.04.

Docker Environment

lient: Docker Engine - Community
 Version:    27.3.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.17.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.29.7
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions