diff --git a/cmd/compose/run.go b/cmd/compose/run.go index c18fdf2375..cb6a127c98 100644 --- a/cmd/compose/run.go +++ b/cmd/compose/run.go @@ -142,6 +142,7 @@ func (options runOptions) getEnvironment(resolve func(string) (string, bool)) (t return environment, nil } +//nolint:gocyclo func runCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command { options := runOptions{ composeOptions: &composeOptions{ @@ -190,6 +191,9 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *Backen // we don't have an actual terminal to attach to for interactive mode options.noTty = true } + if createOpts.Build && createOpts.noBuild { + return fmt.Errorf("--build and --no-build are incompatible") + } if options.quiet { display.Mode = display.ModeQuiet @@ -246,6 +250,7 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *Backen flags.BoolVar(&buildOpts.quiet, "quiet-build", false, "Suppress progress output from the build process") flags.BoolVar(&options.quietPull, "quiet-pull", false, "Pull without printing progress information") flags.BoolVar(&createOpts.Build, "build", false, "Build image before starting container") + flags.BoolVar(&createOpts.noBuild, "no-build", false, "Don't build an image, even if it's policy") flags.BoolVar(&options.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file") cmd.Flags().BoolVarP(&options.interactive, "interactive", "i", true, "Keep STDIN open even if not attached") diff --git a/docs/reference/compose_run.md b/docs/reference/compose_run.md index 25b28d1ded..3566c54089 100644 --- a/docs/reference/compose_run.md +++ b/docs/reference/compose_run.md @@ -71,6 +71,7 @@ specified in the service configuration. | `-l`, `--label` | `stringArray` | | Add or override a label | | `--name` | `string` | | Assign a name to the container | | `-T`, `--no-TTY` | `bool` | `true` | Disable pseudo-TTY allocation (default: auto-detected) | +| `--no-build` | `bool` | | Don't build an image, even if it's policy | | `--no-deps` | `bool` | | Don't start linked services | | `-p`, `--publish` | `stringArray` | | Publish a container's port(s) to the host | | `--pull` | `string` | `policy` | Pull image before running ("always"\|"missing"\|"never") | diff --git a/docs/reference/docker_compose_run.yaml b/docs/reference/docker_compose_run.yaml index 61c7ca0e8c..9263242903 100644 --- a/docs/reference/docker_compose_run.yaml +++ b/docs/reference/docker_compose_run.yaml @@ -169,6 +169,16 @@ options: experimentalcli: false kubernetes: false swarm: false + - option: no-build + value_type: bool + default_value: "false" + description: Don't build an image, even if it's policy + deprecated: false + hidden: false + experimental: false + experimentalcli: false + kubernetes: false + swarm: false - option: no-deps value_type: bool default_value: "false"