mirror of https://github.com/docker/cli.git
Merge pull request #30383 from TDAbboud/30096-add-host-docker-build
Add --add-host for docker build
This commit is contained in:
commit
7665cb52dc
|
@ -38,6 +38,7 @@ type buildOptions struct {
|
||||||
tags opts.ListOpts
|
tags opts.ListOpts
|
||||||
labels opts.ListOpts
|
labels opts.ListOpts
|
||||||
buildArgs opts.ListOpts
|
buildArgs opts.ListOpts
|
||||||
|
extraHosts opts.ListOpts
|
||||||
ulimits *opts.UlimitOpt
|
ulimits *opts.UlimitOpt
|
||||||
memory string
|
memory string
|
||||||
memorySwap string
|
memorySwap string
|
||||||
|
@ -65,10 +66,11 @@ type buildOptions struct {
|
||||||
func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command {
|
func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
ulimits := make(map[string]*units.Ulimit)
|
ulimits := make(map[string]*units.Ulimit)
|
||||||
options := buildOptions{
|
options := buildOptions{
|
||||||
tags: opts.NewListOpts(validateTag),
|
tags: opts.NewListOpts(validateTag),
|
||||||
buildArgs: opts.NewListOpts(opts.ValidateEnv),
|
buildArgs: opts.NewListOpts(opts.ValidateEnv),
|
||||||
ulimits: opts.NewUlimitOpt(&ulimits),
|
ulimits: opts.NewUlimitOpt(&ulimits),
|
||||||
labels: opts.NewListOpts(opts.ValidateEnv),
|
labels: opts.NewListOpts(opts.ValidateEnv),
|
||||||
|
extraHosts: opts.NewListOpts(opts.ValidateExtraHost),
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
|
@ -108,6 +110,7 @@ func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
flags.StringSliceVar(&options.securityOpt, "security-opt", []string{}, "Security options")
|
flags.StringSliceVar(&options.securityOpt, "security-opt", []string{}, "Security options")
|
||||||
flags.StringVar(&options.networkMode, "network", "default", "Set the networking mode for the RUN instructions during build")
|
flags.StringVar(&options.networkMode, "network", "default", "Set the networking mode for the RUN instructions during build")
|
||||||
flags.SetAnnotation("network", "version", []string{"1.25"})
|
flags.SetAnnotation("network", "version", []string{"1.25"})
|
||||||
|
flags.Var(&options.extraHosts, "add-host", "Add a custom host-to-IP mapping (host:ip)")
|
||||||
|
|
||||||
command.AddTrustVerificationFlags(flags)
|
command.AddTrustVerificationFlags(flags)
|
||||||
|
|
||||||
|
@ -301,6 +304,7 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
|
||||||
SecurityOpt: options.securityOpt,
|
SecurityOpt: options.securityOpt,
|
||||||
NetworkMode: options.networkMode,
|
NetworkMode: options.networkMode,
|
||||||
Squash: options.squash,
|
Squash: options.squash,
|
||||||
|
ExtraHosts: options.extraHosts.GetAll(),
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := dockerCli.Client().ImageBuild(ctx, body, buildOptions)
|
response, err := dockerCli.Client().ImageBuild(ctx, body, buildOptions)
|
||||||
|
|
Loading…
Reference in New Issue