Skip to content

Commit 83150bd

Browse files
committed
Add the --no-build option to run
`docker compose up` supports `--no-build` but `run` doesn't expose it, even though it has the `--build` option. Fix that omission. Signed-off-by: Aleksei Besogonov <b@alex.net>
1 parent 4f419e5 commit 83150bd

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

cmd/compose/run.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func (options runOptions) getEnvironment(resolve func(string) (string, bool)) (t
142142
return environment, nil
143143
}
144144

145+
//nolint:gocyclo
145146
func runCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command {
146147
options := runOptions{
147148
composeOptions: &composeOptions{
@@ -190,6 +191,9 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *Backen
190191
// we don't have an actual terminal to attach to for interactive mode
191192
options.noTty = true
192193
}
194+
if createOpts.Build && createOpts.noBuild {
195+
return fmt.Errorf("--build and --no-build are incompatible")
196+
}
193197

194198
if options.quiet {
195199
display.Mode = display.ModeQuiet
@@ -246,6 +250,7 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *Backen
246250
flags.BoolVar(&buildOpts.quiet, "quiet-build", false, "Suppress progress output from the build process")
247251
flags.BoolVar(&options.quietPull, "quiet-pull", false, "Pull without printing progress information")
248252
flags.BoolVar(&createOpts.Build, "build", false, "Build image before starting container")
253+
flags.BoolVar(&createOpts.noBuild, "no-build", false, "Don't build an image, even if it's policy")
249254
flags.BoolVar(&options.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file")
250255

251256
cmd.Flags().BoolVarP(&options.interactive, "interactive", "i", true, "Keep STDIN open even if not attached")

docs/reference/compose_run.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ specified in the service configuration.
7171
| `-l`, `--label` | `stringArray` | | Add or override a label |
7272
| `--name` | `string` | | Assign a name to the container |
7373
| `-T`, `--no-TTY` | `bool` | `true` | Disable pseudo-TTY allocation (default: auto-detected) |
74+
| `--no-build` | `bool` | | Don't build an image, even if it's policy |
7475
| `--no-deps` | `bool` | | Don't start linked services |
7576
| `-p`, `--publish` | `stringArray` | | Publish a container's port(s) to the host |
7677
| `--pull` | `string` | `policy` | Pull image before running ("always"\|"missing"\|"never") |

docs/reference/docker_compose_run.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ options:
169169
experimentalcli: false
170170
kubernetes: false
171171
swarm: false
172+
- option: no-build
173+
value_type: bool
174+
default_value: "false"
175+
description: Don't build an image, even if it's policy
176+
deprecated: false
177+
hidden: false
178+
experimental: false
179+
experimentalcli: false
180+
kubernetes: false
181+
swarm: false
172182
- option: no-deps
173183
value_type: bool
174184
default_value: "false"

0 commit comments

Comments
 (0)