docker/cli · error

conflicting options: cannot specify both --timeout and…

Error message

conflicting options: cannot specify both --timeout and --time

What it means

Returned by the stop command when both --timeout and the deprecated --time are provided. Identical guard to restart: both flags alias the same timeout field, so setting both is ambiguous and rejected at stop.go:32-33. --time exists only for backward compatibility and is marked deprecated.

Solutions

  1. Use only --timeout: `docker stop --timeout 10 ctr`.
  2. Remove the deprecated --time from automation.
  3. Normalize flags to --timeout in your command builder before invoking docker.

Example fix

// before
docker stop --time 10 --timeout 20 ctr

// after
docker stop --timeout 10 ctr
Defensive patterns

Strategy: validation

Validate before calling

func normalizeStopTimeout(hasTime, hasTimeout bool) error {
    if hasTime && hasTimeout {
        return errors.New("conflicting options: cannot specify both --timeout and --time")
    }
    return nil
}

Prevention

When it happens

Trigger: `docker stop --time 10 --timeout 20 ctr`. Both flags Changed triggers the error.

Common situations: Legacy scripts with --time being migrated to --timeout with both left in. Wrapper/alias tooling appending flags. Copy-paste from mixed references.

Understand the failure class

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/a21d76814476f729. Report an issue: GitHub.

Appendix: source

Thrown at cli/command/container/stop.go:33

type stopOptions struct {
	signal         string
	timeout        int
	timeoutChanged bool

	containers []string
}

// newStopCommand creates a new cobra.Command for "docker container stop".
func newStopCommand(dockerCLI command.Cli) *cobra.Command {
	var opts stopOptions

	cmd := &cobra.Command{
		Use:   "stop [OPTIONS] CONTAINER [CONTAINER...]",
		Short: "Stop one or more running containers",
		Args:  cli.RequiresMinArgs(1),
		RunE: func(cmd *cobra.Command, args []string) error {
			if cmd.Flags().Changed("time") && cmd.Flags().Changed("timeout") {
				return errors.New("conflicting options: cannot specify both --timeout and --time")
			}
			opts.containers = args
			opts.timeoutChanged = cmd.Flags().Changed("timeout") || cmd.Flags().Changed("time")
			return runStop(cmd.Context(), dockerCLI, &opts)
		},
		Annotations: map[string]string{
			"aliases": "docker container stop, docker stop",
		},
		ValidArgsFunction:     completion.ContainerNames(dockerCLI, false),
		DisableFlagsInUseLine: true,
	}

	flags := cmd.Flags()
	flags.StringVarP(&opts.signal, "signal", "s", "", "Signal to send to the container")
	flags.IntVarP(&opts.timeout, "timeout", "t", 0, "Seconds to wait before killing the container")

	// The --time option is deprecated, but kept for backward compatibility.
	flags.IntVar(&opts.timeout, "time", 0, "Seconds to wait before killing the container (deprecated: use --timeout)")

View on GitHub (pinned to 4f84911bfe)