Settings environment variables in CI not affecting compose

I’m running docker compose as part of my test job in gitlab ci (global gitlab.com).

// docker-compose.yaml
  some-service:
    ...
    environment:
      MY_ENV: ${MY_ENV}

// .gitlab-ci.yml
test:
  image: docker:git
  script:
    ...
    - docker compose --env-file .env up --wait
  variables:
    MY_ENV: env_value

// .env
MY_ENV=file_value

There is a value from the .env file that is injected to some_service.
In the CI I try to override it by setting the variable to another value.
Running the same command locally does change the env var inside the service, but in the CI it doesn’t work.
What am I doing wrong?