{"record":{"id":"888ea23961a6c305","repo":"docker/cli","slug":"conflicting-options-cannot-specify-both-timeout","errorCode":null,"errorMessage":"conflicting options: cannot specify both --timeout and --time","messagePattern":"conflicting options: cannot specify both --timeout and --time","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/restart.go","lineNumber":33,"sourceCode":"type restartOptions struct {\n\tsignal         string\n\ttimeout        int\n\ttimeoutChanged bool\n\n\tcontainers []string\n}\n\n// newRestartCommand creates a new cobra.Command for \"docker container restart\".\nfunc newRestartCommand(dockerCLI command.Cli) *cobra.Command {\n\tvar opts restartOptions\n\n\tcmd := &cobra.Command{\n\t\tUse:   \"restart [OPTIONS] CONTAINER [CONTAINER...]\",\n\t\tShort: \"Restart one or more containers\",\n\t\tArgs:  cli.RequiresMinArgs(1),\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\tif cmd.Flags().Changed(\"time\") && cmd.Flags().Changed(\"timeout\") {\n\t\t\t\treturn errors.New(\"conflicting options: cannot specify both --timeout and --time\")\n\t\t\t}\n\t\t\topts.containers = args\n\t\t\topts.timeoutChanged = cmd.Flags().Changed(\"timeout\") || cmd.Flags().Changed(\"time\")\n\t\t\treturn runRestart(cmd.Context(), dockerCLI, &opts)\n\t\t},\n\t\tAnnotations: map[string]string{\n\t\t\t\"aliases\": \"docker container restart, docker restart\",\n\t\t},\n\t\tValidArgsFunction:     completion.ContainerNames(dockerCLI, true),\n\t\tDisableFlagsInUseLine: true,\n\t}\n\n\tflags := cmd.Flags()\n\tflags.StringVarP(&opts.signal, \"signal\", \"s\", \"\", \"Signal to send to the container\")\n\tflags.IntVarP(&opts.timeout, \"timeout\", \"t\", 0, \"Seconds to wait before killing the container\")\n\n\t// The --time option is deprecated, but kept for backward compatibility.\n\tflags.IntVar(&opts.timeout, \"time\", 0, \"Seconds to wait before killing the container (deprecated: use --timeout)\")","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/restart.go#L15-L51","documentation":"Returned by the restart command when both --timeout and the deprecated --time are set on the same invocation. Both flags bind to the same timeout value, so providing both is ambiguous; the CLI explicitly checks cmd.Flags().Changed for both and rejects the combination. --time is kept only for backward compatibility and marked deprecated.","triggerScenarios":"`docker restart --time 10 --timeout 20 ctr`. Both flags present triggers the guard at restart.go:32-33.","commonSituations":"Old scripts using --time being gradually migrated to --timeout but both left in during transition. Wrapper scripts concatenating flags. Copy-pasting from two references that use different flags.","solutions":["Use only --timeout (the supported flag): `docker restart --timeout 10 ctr`.","Remove the deprecated --time from scripts and aliases.","If automating, normalize to --timeout in your flag builder before invoking docker."],"exampleFix":"// before\ndocker restart --time 10 --timeout 20 ctr\n\n// after\ndocker restart --timeout 10 ctr","handlingStrategy":"validation","validationCode":"// Normalize to --timeout only before invoking restart.\nfunc normalizeRestartTimeout(hasTime, hasTimeout bool) error {\n    if hasTime && hasTimeout {\n        return errors.New(\"conflicting options: cannot specify both --timeout and --time\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize all scripts on --timeout; remove --time.","In wrapper tools, never emit both flags; translate --time to --timeout once.","Add a lint rule that flags --time usage alongside --timeout."],"tags":["cli-options","conflicting-flags","deprecated","container","restart"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}