Merge pull request #10007 from laurazard/add-build-run
Add `--build` to `compose run`
This commit is contained in:
commit
88c3aaf1bf
@ -113,6 +113,7 @@ func runCommand(p *projectOptions, dockerCli command.Cli, backend api.Service) *
|
|||||||
projectOptions: p,
|
projectOptions: p,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
createOpts := createOptions{}
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "run [OPTIONS] SERVICE [COMMAND] [ARGS...]",
|
Use: "run [OPTIONS] SERVICE [COMMAND] [ARGS...]",
|
||||||
Short: "Run a one-off command on a service.",
|
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"]
|
ignore := project.Environment["COMPOSE_IGNORE_ORPHANS"]
|
||||||
opts.ignoreOrphans = strings.ToLower(ignore) == "true"
|
opts.ignoreOrphans = strings.ToLower(ignore) == "true"
|
||||||
return runRun(ctx, backend, project, opts)
|
return runRun(ctx, backend, project, opts, createOpts)
|
||||||
}),
|
}),
|
||||||
ValidArgsFunction: completeServiceNames(p),
|
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.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.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(&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().BoolVarP(&opts.interactive, "interactive", "i", true, "Keep STDIN open even if not attached.")
|
||||||
cmd.Flags().BoolP("tty", "t", true, "Allocate a pseudo-TTY.")
|
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)
|
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)
|
err := opts.apply(project)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createOpts.Apply(project)
|
||||||
|
|
||||||
err = progress.Run(ctx, func(ctx context.Context) error {
|
err = progress.Run(ctx, func(ctx context.Context) error {
|
||||||
return startDependencies(ctx, backend, *project, opts.Service, opts.ignoreOrphans)
|
return startDependencies(ctx, backend, *project, opts.Service, opts.ignoreOrphans)
|
||||||
})
|
})
|
||||||
|
@ -7,6 +7,7 @@ Run a one-off command on a service.
|
|||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
|
| `--build` | | | Build image before starting container. |
|
||||||
| `-d`, `--detach` | | | Run container in background and print container ID |
|
| `-d`, `--detach` | | | Run container in background and print container ID |
|
||||||
| `--entrypoint` | `string` | | Override the entrypoint of the image |
|
| `--entrypoint` | `string` | | Override the entrypoint of the image |
|
||||||
| `-e`, `--env` | `stringArray` | | Set environment variables |
|
| `-e`, `--env` | `stringArray` | | Set environment variables |
|
||||||
|
@ -58,6 +58,16 @@ usage: docker compose run [OPTIONS] SERVICE [COMMAND] [ARGS...]
|
|||||||
pname: docker compose
|
pname: docker compose
|
||||||
plink: docker_compose.yaml
|
plink: docker_compose.yaml
|
||||||
options:
|
options:
|
||||||
|
- option: build
|
||||||
|
value_type: bool
|
||||||
|
default_value: "false"
|
||||||
|
description: Build image before starting container.
|
||||||
|
deprecated: false
|
||||||
|
hidden: false
|
||||||
|
experimental: false
|
||||||
|
experimentalcli: false
|
||||||
|
kubernetes: false
|
||||||
|
swarm: false
|
||||||
- option: detach
|
- option: detach
|
||||||
shorthand: d
|
shorthand: d
|
||||||
value_type: bool
|
value_type: bool
|
||||||
|
Loading…
x
Reference in New Issue
Block a user