diff --git a/cmd/compose/create.go b/cmd/compose/create.go index 9379818dd..4c8d68628 100644 --- a/cmd/compose/create.go +++ b/cmd/compose/create.go @@ -19,6 +19,7 @@ package compose import ( "context" "fmt" + "slices" "strconv" "strings" "time" @@ -138,6 +139,9 @@ func (opts createOptions) GetTimeout() *time.Duration { func (opts createOptions) Apply(project *types.Project) error { if opts.pullChanged { + if !opts.isPullPolicyValid() { + return fmt.Errorf("invalid --pull option %q", opts.Pull) + } for i, service := range project.Services { service.PullPolicy = opts.Pull project.Services[i] = service @@ -187,3 +191,9 @@ func (opts createOptions) Apply(project *types.Project) error { } return nil } + +func (opts createOptions) isPullPolicyValid() bool { + pullPolicies := []string{types.PullPolicyAlways, types.PullPolicyNever, types.PullPolicyBuild, + types.PullPolicyMissing, types.PullPolicyIfNotPresent} + return slices.Contains(pullPolicies, opts.Pull) +}