compose icon indicating copy to clipboard operation
compose copied to clipboard

Add support to pass env-file to docker compose run

Open KoditkarVedant opened this issue 3 years ago • 5 comments

What I did This pull request adds support to pass in --env-file to docker compose run command.

Behavior of the option: If you pass env-file from CLI it overrides the env-files provided in docker-compose.yaml config.

Related issue #8379

(not mandatory) A picture of a cute animal, if possible in relation with what you did image

KoditkarVedant avatar Feb 13 '22 20:02 KoditkarVedant

command documentation also need to be updated to reflect this new flag: https://github.com/docker/compose/blob/v2/docs/reference/docker_compose_run.yaml

ndeloof avatar Mar 01 '22 08:03 ndeloof

@ndeloof Looks like there is bug in the implementation. It isn't working as expected. I think when we parse the compose config files at that time only the env_file mentioned in it gets parsed. because when I see the service.Environment it was already populated with the key=value mentioned in the env_file. So my understanding that just replacing the service.EnvFile will work is not true.

I'll just put back this PR in draft as it is not ready for merge.

KoditkarVedant avatar Mar 02 '22 16:03 KoditkarVedant

The main issue I see adding support for compose run --env-file ... to set container environment from a file (which would make sense to align with docker run ...) is that this will introduce confusion with the top-level --env-file used to override .env file used to interpolate variables. i.e. docker compose --env-file xx run is a distinct thing vs docker compose run --env-file xx I'm not sure how we could address this UX issue. Any thoughts @glours @ulyssessouza @thaJeztah ?

ndeloof avatar Mar 11 '22 13:03 ndeloof

Same for me... The UX doesn't help... And specially because the new one is an array and the root command one is a single file.

ulyssessouza avatar Jul 13 '22 03:07 ulyssessouza

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 73.89%. Comparing base (d47f0f3) to head (bfb8c20). Report is 1239 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9169   +/-   ##
=======================================
  Coverage   73.89%   73.89%           
=======================================
  Files           2        2           
  Lines         272      272           
=======================================
  Hits          201      201           
  Misses         60       60           
  Partials       11       11           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Jan 24 '23 18:01 codecov[bot]

This issue has been automatically marked as not stale anymore due to the recent activity.

stale[bot] avatar Mar 11 '25 14:03 stale[bot]

This issue has been automatically marked as not stale anymore due to the recent activity.

stale[bot] avatar Mar 11 '25 14:03 stale[bot]

This issue has been automatically marked as not stale anymore due to the recent activity.

stale[bot] avatar Mar 11 '25 14:03 stale[bot]

I cherry-picked your code into https://github.com/docker/compose/pull/12626

ndeloof avatar Mar 14 '25 09:03 ndeloof