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

Function newCreateCommand

cli/command/service/create.go:17–94  ·  view source on GitHub ↗
(dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

15)
16
17func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
18 opts := newServiceOptions()
19
20 cmd := &cobra.Command{
21 Use: "create [OPTIONS] IMAGE [COMMAND] [ARG...]",
22 Short: "Create a new service",
23 Args: cli.RequiresMinArgs(1),
24 RunE: func(cmd *cobra.Command, args []string) error {
25 opts.image = args[0]
26 if len(args) > 1 {
27 opts.args = args[1:]
28 }
29 return runCreate(cmd.Context(), dockerCLI, cmd.Flags(), opts)
30 },
31 ValidArgsFunction: cobra.NoFileCompletions,
32 DisableFlagsInUseLine: true,
33 }
34 flags := cmd.Flags()
35 flags.StringVar(&opts.mode, flagMode, "replicated", `Service mode ("replicated", "global", "replicated-job", "global-job")`)
36 flags.StringVar(&opts.name, flagName, "", "Service name")
37
38 addServiceFlags(flags, opts, buildServiceDefaultFlagMapping())
39
40 flags.VarP(&opts.labels, flagLabel, "l", "Service labels")
41 flags.Var(&opts.containerLabels, flagContainerLabel, "Container labels")
42 flags.VarP(&opts.env, flagEnv, "e", "Set environment variables")
43 flags.Var(&opts.envFile, flagEnvFile, "Read in a file of environment variables")
44 flags.Var(&opts.mounts, flagMount, "Attach a filesystem mount to the service")
45 flags.Var(&opts.constraints, flagConstraint, "Placement constraints")
46 flags.Var(&opts.placementPrefs, flagPlacementPref, "Add a placement preference")
47 flags.SetAnnotation(flagPlacementPref, "version", []string{"1.28"})
48 flags.Var(&opts.networks, flagNetwork, "Network attachments")
49 flags.Var(&opts.secrets, flagSecret, "Specify secrets to expose to the service")
50 flags.SetAnnotation(flagSecret, "version", []string{"1.25"})
51 flags.Var(&opts.configs, flagConfig, "Specify configurations to expose to the service")
52 flags.SetAnnotation(flagConfig, "version", []string{"1.30"})
53 flags.VarP(&opts.endpoint.publishPorts, flagPublish, "p", "Publish a port as a node port")
54 flags.Var(&opts.groups, flagGroup, "Set one or more supplementary user groups for the container")
55 flags.SetAnnotation(flagGroup, "version", []string{"1.25"})
56 flags.Var(&opts.dns, flagDNS, "Set custom DNS servers")
57 flags.SetAnnotation(flagDNS, "version", []string{"1.25"})
58 flags.Var(&opts.dnsOption, flagDNSOption, "Set DNS options")
59 flags.SetAnnotation(flagDNSOption, "version", []string{"1.25"})
60 flags.Var(&opts.dnsSearch, flagDNSSearch, "Set custom DNS search domains")
61 flags.SetAnnotation(flagDNSSearch, "version", []string{"1.25"})
62 flags.Var(&opts.hosts, flagHost, "Set one or more custom host-to-IP mappings (host:ip)")
63 flags.SetAnnotation(flagHost, "version", []string{"1.25"})
64 flags.BoolVar(&opts.init, flagInit, false, "Use an init inside each service container to forward signals and reap processes")
65 flags.SetAnnotation(flagInit, "version", []string{"1.37"})
66 flags.Var(&opts.sysctls, flagSysCtl, "Sysctl options")
67 flags.SetAnnotation(flagSysCtl, "version", []string{"1.40"})
68 flags.Var(&opts.ulimits, flagUlimit, "Ulimit options")
69 flags.SetAnnotation(flagUlimit, "version", []string{"1.41"})
70 flags.Int64Var(&opts.oomScoreAdj, flagOomScoreAdj, 0, "Tune host's OOM preferences (-1000 to 1000) ")
71 flags.SetAnnotation(flagOomScoreAdj, "version", []string{"1.46"})
72
73 flags.Var(cliopts.NewListOptsRef(&opts.resources.resGenericResources, ValidateSingleGenericResource), "generic-resource", "User defined resources")
74 flags.SetAnnotation(flagHostAdd, "version", []string{"1.32"})

Calls 4

newServiceOptionsFunction · 0.85
addServiceFlagsFunction · 0.85
runCreateFunction · 0.70

Used in the wild real call sites across dependent graphs

searching dependent graphs…