diff --git a/cmd/compose/run.go b/cmd/compose/run.go index 9922d792c..f2611cd6e 100644 --- a/cmd/compose/run.go +++ b/cmd/compose/run.go @@ -113,6 +113,7 @@ func runCommand(p *projectOptions, dockerCli command.Cli, backend api.Service) * projectOptions: p, }, } + createOpts := createOptions{} cmd := &cobra.Command{ Use: "run [OPTIONS] SERVICE [COMMAND] [ARGS...]", Short: "Run a one-off command on a service.", @@ -141,7 +142,7 @@ func runCommand(p *projectOptions, dockerCli command.Cli, backend api.Service) * } ignore := project.Environment["COMPOSE_IGNORE_ORPHANS"] opts.ignoreOrphans = strings.ToLower(ignore) == "true" - return runRun(ctx, backend, project, opts) + return runRun(ctx, backend, project, opts, createOpts) }), ValidArgsFunction: completeServiceNames(p), } @@ -161,6 +162,7 @@ func runCommand(p *projectOptions, dockerCli command.Cli, backend api.Service) * flags.BoolVar(&opts.useAliases, "use-aliases", false, "Use the service's network useAliases in the network(s) the container connects to.") flags.BoolVar(&opts.servicePorts, "service-ports", false, "Run command with the service's ports enabled and mapped to the host.") flags.BoolVar(&opts.quietPull, "quiet-pull", false, "Pull without printing progress information.") + flags.BoolVar(&createOpts.Build, "build", false, "Build image before starting container.") cmd.Flags().BoolVarP(&opts.interactive, "interactive", "i", true, "Keep STDIN open even if not attached.") cmd.Flags().BoolP("tty", "t", true, "Allocate a pseudo-TTY.") @@ -181,12 +183,14 @@ func normalizeRunFlags(f *pflag.FlagSet, name string) pflag.NormalizedName { return pflag.NormalizedName(name) } -func runRun(ctx context.Context, backend api.Service, project *types.Project, opts runOptions) error { +func runRun(ctx context.Context, backend api.Service, project *types.Project, opts runOptions, createOpts createOptions) error { err := opts.apply(project) if err != nil { return err } + createOpts.Apply(project) + err = progress.Run(ctx, func(ctx context.Context) error { return startDependencies(ctx, backend, *project, opts.Service, opts.ignoreOrphans) })