Skip to content

Official expected behavior about default ENV variables set in images and listed in docker-compose manifest #11962

@remiville-nx

Description

@remiville-nx

Description

I found an important difference in docker-compose behavior regarding default variables set in images, since v2.24.7.

Knowing that we have an image containing a variable "VAR" with a default value "default", the Dockerfile specifies:
ENV VAR "default"

If the environment section of the docker-compose manifest specifies a variable "VAR" (without value):

  • Before v2.24.7: the variable is unset from the container (the "default" value is lost)
  • Since v2.24.7: the variable with its default value is kept in the container

Regardless of the version, if the environment section of the docker-compose manifest specifies "VAR=" (with the equal sign and no value), the variable is set as empty in the container.

This difference in behavior is important because:

  • If you deploy your images with docker-compose or another orchestrator you want your default variables being defined in images (not in .env or docker-compose manifest).
  • If you want to override one of these variables just by setting it in .env or in the execution context (export VAR=...) you need to specify it in the environment section of the docker-compose manifest, if not the variable will not be passed to the container.

For me the behavior since v2.24.7 is the good one, but it doesn't appear in changelog, I don't even not know which issue or commit changed this, it's maybe just a side effect.

Can you confirm this behavior introduced by v2.24.7 is the expected one and can you add it to the official documentation ?
If a unit test could ensure this behavior will not be lost it would be great.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions