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

Function newRunCommand

cli/command/container/run.go:33–85  ·  view source on GitHub ↗

newRunCommand create a new "docker run" command.

(dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

31
32// newRunCommand create a new "docker run" command.
33func newRunCommand(dockerCLI command.Cli) *cobra.Command {
34 var options runOptions
35 var copts *containerOptions
36
37 cmd := &cobra.Command{
38 Use: "run [OPTIONS] IMAGE [COMMAND] [ARG...]",
39 Short: "Create and run a new container from an image",
40 Args: cli.RequiresMinArgs(1),
41 RunE: func(cmd *cobra.Command, args []string) error {
42 copts.Image = args[0]
43 if len(args) > 1 {
44 copts.Args = args[1:]
45 }
46 return runRun(cmd.Context(), dockerCLI, cmd.Flags(), &options, copts)
47 },
48 ValidArgsFunction: completion.ImageNames(dockerCLI, 1),
49 Annotations: map[string]string{
50 "category-top": "1",
51 "aliases": "docker container run, docker run",
52 },
53 DisableFlagsInUseLine: true,
54 }
55
56 flags := cmd.Flags()
57 flags.SetInterspersed(false)
58
59 // These are flags not stored in Config/HostConfig
60 flags.BoolVarP(&options.detach, "detach", "d", false, "Run container in background and print container ID")
61 flags.BoolVar(&options.sigProxy, "sig-proxy", true, "Proxy received signals to the process")
62 flags.StringVar(&options.name, "name", "", "Assign a name to the container")
63 flags.StringVar(&options.detachKeys, "detach-keys", "", "Override the key sequence for detaching a container")
64 flags.StringVar(&options.pull, "pull", PullImageMissing, `Pull image before running ("`+PullImageAlways+`", "`+PullImageMissing+`", "`+PullImageNever+`")`)
65 flags.BoolVarP(&options.quiet, "quiet", "q", false, "Suppress the pull output")
66 flags.BoolVarP(&options.createOptions.useAPISocket, "use-api-socket", "", false, "Bind mount Docker API socket and required auth")
67
68 // Add an explicit help that doesn't have a `-h` to prevent the conflict
69 // with hostname
70 flags.Bool("help", false, "Print usage")
71
72 // TODO(thaJeztah): consider adding platform as "image create option" on containerOptions
73 flags.StringVar(&options.platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
74 _ = flags.SetAnnotation("platform", "version", []string{"1.32"})
75
76 // TODO(thaJeztah): DEPRECATED: remove in v29.1 or v30
77 flags.Bool("disable-content-trust", true, "Skip image verification (deprecated)")
78 _ = flags.MarkDeprecated("disable-content-trust", "support for docker content trust was removed")
79 copts = addFlags(flags)
80
81 _ = cmd.RegisterFlagCompletionFunc("detach-keys", completeDetachKeys)
82 addCompletions(cmd, dockerCLI)
83
84 return cmd
85}
86
87func runRun(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, ropts *runOptions, copts *containerOptions) error {
88 if err := validatePullOpt(ropts.pull); err != nil {

Callers 7

newContainerCommandFunction · 0.85
TestCompletePidFunction · 0.85
TestRunValidateFlagsFunction · 0.85
TestRunLabelFunction · 0.85
TestRunAttachFunction · 0.85
TestRunAttachTerminationFunction · 0.85
TestRunPullTerminationFunction · 0.85

Calls 3

runRunFunction · 0.85
addFlagsFunction · 0.85
addCompletionsFunction · 0.85

Tested by 6

TestCompletePidFunction · 0.68
TestRunValidateFlagsFunction · 0.68
TestRunLabelFunction · 0.68
TestRunAttachFunction · 0.68
TestRunAttachTerminationFunction · 0.68
TestRunPullTerminationFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…