-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Add support to pass env-file to docker compose run #9169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to pass env-file to docker compose run #9169
Conversation
25c370a to
5a1f2bd
Compare
|
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 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 I'll just put back this PR in draft as it is not ready for merge. |
|
The main issue I see adding support for |
|
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. |
cmd/compose/run.go
Outdated
| flags := cmd.Flags() | ||
| flags.BoolVarP(&opts.Detach, "detach", "d", false, "Run container in background and print container ID") | ||
| flags.StringArrayVarP(&opts.environment, "env", "e", []string{}, "Set environment variables") | ||
| flags.StringArrayVar(&opts.EnvFiles, "env-file", []string{}, "Read in a file of environment variables") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we use --service-env-file to avoid ambiguity with upper-level compose command --env-file flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to retain a parallel between docker run and docker compose run, then I'm wondering if we should look at doing the reverse, and think of a new name for the flag for setting the .env (we could keep the old flag, but hidden)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed the option to service-env-file
a877dc5 to
5b7b2a3
Compare
Signed-off-by: Vedant Koditkar <vedant.koditkar@outlook.com>
Signed-off-by: Vedant Koditkar <vedant.koditkar@outlook.com>
5b7b2a3 to
bfb8c20
Compare
ndeloof
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but path to service env file passed by command line flag could be relative to working directory
| } | ||
|
|
||
| if opts.ServiceEnvFiles != nil { | ||
| service.EnvFile = append(service.EnvFile, opts.ServiceEnvFiles...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to make service envfile an absolute path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any sample code which I can refer in the repository?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just use:
if !filepath.IsAbs(file) {
file, err = filepath.Abs(file)
}
Codecov ReportAll modified and coverable lines are covered by tests ✅
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 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| flags := cmd.Flags() | ||
| flags.BoolVarP(&opts.Detach, "detach", "d", false, "Run container in background and print container ID") | ||
| flags.StringArrayVarP(&opts.environment, "env", "e", []string{}, "Set environment variables") | ||
| flags.StringArrayVar(&opts.ServiceEnvFiles, "service-env-file", []string{}, "Read in a file of environment variables") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: rename flag --env-from-file, wdyt ?
|
This issue has been automatically marked as not stale anymore due to the recent activity. |
2 similar comments
|
This issue has been automatically marked as not stale anymore due to the recent activity. |
|
This issue has been automatically marked as not stale anymore due to the recent activity. |
|
I cherry-picked your code into #12626 |
What I did
This pull request adds support to pass in
--env-filetodocker compose runcommand.Behavior of the option:
If you pass env-file from CLI it overrides the env-files provided in
docker-compose.yamlconfig.Related issue
#8379
(not mandatory) A picture of a cute animal, if possible in relation with what you did
