MCPcopy Index your code
hub / github.com/docker/cli / newStopCommand

Function newStopCommand

cli/command/container/stop.go:24–57  ·  view source on GitHub ↗

newStopCommand creates a new cobra.Command for "docker container stop".

(dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

22
23// newStopCommand creates a new cobra.Command for "docker container stop".
24func newStopCommand(dockerCLI command.Cli) *cobra.Command {
25 var opts stopOptions
26
27 cmd := &cobra.Command{
28 Use: "stop [OPTIONS] CONTAINER [CONTAINER...]",
29 Short: "Stop one or more running containers",
30 Args: cli.RequiresMinArgs(1),
31 RunE: func(cmd *cobra.Command, args []string) error {
32 if cmd.Flags().Changed("time") && cmd.Flags().Changed("timeout") {
33 return errors.New("conflicting options: cannot specify both --timeout and --time")
34 }
35 opts.containers = args
36 opts.timeoutChanged = cmd.Flags().Changed("timeout") || cmd.Flags().Changed("time")
37 return runStop(cmd.Context(), dockerCLI, &opts)
38 },
39 Annotations: map[string]string{
40 "aliases": "docker container stop, docker stop",
41 },
42 ValidArgsFunction: completion.ContainerNames(dockerCLI, false),
43 DisableFlagsInUseLine: true,
44 }
45
46 flags := cmd.Flags()
47 flags.StringVarP(&opts.signal, "signal", "s", "", "Signal to send to the container")
48 flags.IntVarP(&opts.timeout, "timeout", "t", 0, "Seconds to wait before killing the container")
49
50 // The --time option is deprecated, but kept for backward compatibility.
51 flags.IntVar(&opts.timeout, "time", 0, "Seconds to wait before killing the container (deprecated: use --timeout)")
52 _ = flags.MarkDeprecated("time", "use --timeout instead")
53
54 _ = cmd.RegisterFlagCompletionFunc("signal", completeSignals)
55
56 return cmd
57}
58
59func runStop(ctx context.Context, dockerCLI command.Cli, opts *stopOptions) error {
60 var timeout *int

Callers 2

newContainerCommandFunction · 0.85
TestStopFunction · 0.85

Calls 1

runStopFunction · 0.85

Tested by 1

TestStopFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…