diff --git a/cli/command/container/opts_test.go b/cli/command/container/opts_test.go index 59665b298b72..895c354597a0 100644 --- a/cli/command/container/opts_test.go +++ b/cli/command/container/opts_test.go @@ -714,6 +714,10 @@ func TestParseRestartPolicy(t *testing.T) { Name: container.RestartPolicyDisabled, }, }, + { + input: "no:1", + expectedErr: "invalid restart policy: maximum retry count cannot be used with restart policy 'no'", + }, { input: ":1", expectedErr: "invalid restart policy format: no policy provided before colon", @@ -725,11 +729,8 @@ func TestParseRestartPolicy(t *testing.T) { }, }, { - input: "always:1", - expected: container.RestartPolicy{ - Name: container.RestartPolicyAlways, - MaximumRetryCount: 1, - }, + input: "always:1", + expectedErr: "invalid restart policy: maximum retry count cannot be used with restart policy 'always'", }, { input: "always:2:3", @@ -752,6 +753,10 @@ func TestParseRestartPolicy(t *testing.T) { Name: container.RestartPolicyUnlessStopped, }, }, + { + input: "unless-stopped:1", + expectedErr: "invalid restart policy: maximum retry count cannot be used with restart policy 'unless-stopped'", + }, { input: "unless-stopped:invalid", expectedErr: "invalid restart policy format: maximum retry count must be an integer", diff --git a/opts/parse.go b/opts/parse.go index 381648fe7344..97cef57e9d44 100644 --- a/opts/parse.go +++ b/opts/parse.go @@ -92,5 +92,8 @@ func ParseRestartPolicy(policy string) (container.RestartPolicy, error) { } p.Name = container.RestartPolicyMode(k) + if err := container.ValidateRestartPolicy(p); err != nil { + return container.RestartPolicy{}, err + } return p, nil }