diff --git a/cmd/compose/run.go b/cmd/compose/run.go index fc5f76421f5..e03577b2c21 100644 --- a/cmd/compose/run.go +++ b/cmd/compose/run.go @@ -54,6 +54,7 @@ type runOptions struct { name string noDeps bool quietPull bool + EnvFiles []string } func (opts runOptions) apply(project *types.Project) error { @@ -141,6 +142,7 @@ func runCommand(p *projectOptions, backend api.Service) *cobra.Command { 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") flags.StringArrayVarP(&opts.labels, "label", "l", []string{}, "Add or override a label") flags.BoolVar(&opts.Remove, "rm", false, "Automatically remove the container when it exits") flags.BoolVarP(&opts.noTty, "no-TTY", "T", false, "Disable pseudo-noTty allocation. By default docker compose run allocates a TTY") @@ -212,6 +214,7 @@ func runRun(ctx context.Context, backend api.Service, project *types.Project, op NoDeps: opts.noDeps, Index: 0, QuietPull: opts.quietPull, + EnvFiles: opts.EnvFiles, } exitCode, err := backend.RunOneOffContainer(ctx, project, runOpts) if exitCode != 0 { diff --git a/pkg/api/api.go b/pkg/api/api.go index 5d963569cc3..7e98a5aa2b2 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -230,7 +230,8 @@ type RunOptions struct { // QuietPull makes the pulling process quiet QuietPull bool // used by exec - Index int + Index int + EnvFiles []string } // EventsOptions group options of the Events API diff --git a/pkg/compose/run.go b/pkg/compose/run.go index 42022300f1d..7b89fe7fe67 100644 --- a/pkg/compose/run.go +++ b/pkg/compose/run.go @@ -222,4 +222,8 @@ func applyRunOptions(project *types.Project, service *types.ServiceConfig, opts for k, v := range opts.Labels { service.Labels = service.Labels.Add(k, v) } + + if opts.EnvFiles != nil { + service.EnvFile = opts.EnvFiles + } }