Search code examples
dockerdocker-composedocker-desktop

"docker compose" environment file pass through shell variables don't work anymore


I want to use an environment file (env_file) to pass through untouched shell variables. What's the correct syntax?

My docker-compose.yaml file:

version: "3.9"
services:
  daemon:
    image: my-image
    env_file:
      - ./env/docker.development.env
    ...

My env file (used to work, but no longer works):

ASPNETCORE_ENVIRONMENT=Development
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY

The AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY used to be passed through from the shell variables. It doesn't work anymore.

I tried:

AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}

The resulting environment variables in the container are always empty. The documentation seems to state that it should work.

When doing it from the docker-compose.yaml environment clause, then it works though, i.e.

...
    image: my-image
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}

but I want to do it from a common env_file to avoid repetition for all my services.

Note: Using Docker Desktop for Windows w/ Linux Subsystem version 4.0.1 (68347)


Solution

  • Reading the release notes, I realized there is a new "Docker Compose V2" option.

    Use Docker Compose V2 checkbox

    From the GitHub, there seems to be many issues still with Compose V2 and environment variables. Unchecking the option resolves the problem.