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

Function newBuildCommand

cli/command/image/build.go:93–166  ·  view source on GitHub ↗

newBuildCommand creates a new `docker build` command

(dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

91
92// newBuildCommand creates a new `docker build` command
93func newBuildCommand(dockerCLI command.Cli) *cobra.Command {
94 options := newBuildOptions()
95
96 cmd := &cobra.Command{
97 Use: "build [OPTIONS] PATH | URL | -",
98 Short: "Build an image from a Dockerfile",
99 Args: cli.ExactArgs(1),
100 RunE: func(cmd *cobra.Command, args []string) error {
101 options.context = args[0]
102 return runBuild(cmd.Context(), dockerCLI, options)
103 },
104 Annotations: map[string]string{
105 "category-top": "4",
106 "aliases": "docker image build, docker build, docker builder build",
107 },
108 ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
109 return nil, cobra.ShellCompDirectiveFilterDirs
110 },
111 DisableFlagsInUseLine: true,
112 }
113
114 flags := cmd.Flags()
115
116 flags.VarP(&options.tags, "tag", "t", `Name and optionally a tag in the "name:tag" format`)
117 flags.SetAnnotation("tag", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/buildx/build/#tag"})
118 flags.Var(&options.buildArgs, "build-arg", "Set build-time variables")
119 flags.SetAnnotation("build-arg", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/buildx/build/#build-arg"})
120 flags.Var(options.ulimits, "ulimit", "Ulimit options")
121 flags.StringVarP(&options.dockerfileName, "file", "f", "", `Name of the Dockerfile (Default is "PATH/Dockerfile")`)
122 flags.SetAnnotation("file", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/buildx/build/#file"})
123 flags.VarP(&options.memory, "memory", "m", "Memory limit")
124 flags.Var(&options.memorySwap, "memory-swap", `Swap limit equal to memory plus swap: -1 to enable unlimited swap`)
125 flags.Var(&options.shmSize, "shm-size", `Size of "/dev/shm"`)
126 flags.Int64VarP(&options.cpuShares, "cpu-shares", "c", 0, "CPU shares (relative weight)")
127 flags.Int64Var(&options.cpuPeriod, "cpu-period", 0, "Limit the CPU CFS (Completely Fair Scheduler) period")
128 flags.Int64Var(&options.cpuQuota, "cpu-quota", 0, "Limit the CPU CFS (Completely Fair Scheduler) quota")
129 flags.StringVar(&options.cpuSetCpus, "cpuset-cpus", "", "CPUs in which to allow execution (0-3, 0,1)")
130 flags.StringVar(&options.cpuSetMems, "cpuset-mems", "", "MEMs in which to allow execution (0-3, 0,1)")
131 flags.StringVar(&options.cgroupParent, "cgroup-parent", "", `Set the parent cgroup for the "RUN" instructions during build`)
132 flags.SetAnnotation("cgroup-parent", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/buildx/build/#cgroup-parent"})
133 flags.StringVar(&options.isolation, "isolation", "", "Container isolation technology")
134 flags.Var(&options.labels, "label", "Set metadata for an image")
135 flags.BoolVar(&options.noCache, "no-cache", false, "Do not use cache when building the image")
136 flags.BoolVar(&options.rm, "rm", true, "Remove intermediate containers after a successful build")
137 flags.BoolVar(&options.forceRm, "force-rm", false, "Always remove intermediate containers")
138 flags.BoolVarP(&options.quiet, "quiet", "q", false, "Suppress the build output and print image ID on success")
139 flags.BoolVar(&options.pull, "pull", false, "Always attempt to pull a newer version of the image")
140 flags.StringSliceVar(&options.cacheFrom, "cache-from", []string{}, "Images to consider as cache sources")
141 flags.BoolVar(&options.compress, "compress", false, "Compress the build context using gzip")
142 flags.StringSliceVar(&options.securityOpt, "security-opt", []string{}, "Security options")
143 flags.StringVar(&options.networkMode, "network", "default", "Set the networking mode for the RUN instructions during build")
144 flags.SetAnnotation("network", "version", []string{"1.25"})
145 flags.SetAnnotation("network", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/buildx/build/#network"})
146 flags.Var(&options.extraHosts, "add-host", `Add a custom host-to-IP mapping ("host:ip")`)
147 flags.SetAnnotation("add-host", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/buildx/build/#add-host"})
148 flags.StringVar(&options.target, "target", "", "Set the target build stage to build.")
149 flags.SetAnnotation("target", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/buildx/build/#target"})
150 flags.StringVar(&options.imageIDFile, "iidfile", "", "Write the image ID to the file")

Callers 4

newImageCommandFunction · 0.85
NewBuildCommandFunction · 0.85

Calls 2

newBuildOptionsFunction · 0.85
runBuildFunction · 0.85

Tested by 2

Used in the wild real call sites across dependent graphs

searching dependent graphs…