Skip to content

Commit

Permalink
Merge pull request moby#30383 from TDAbboud/30096-add-host-docker-build
Browse files Browse the repository at this point in the history
Add --add-host for docker build
  • Loading branch information
thaJeztah authored Feb 27, 2017
2 parents 76b6faa + e66e519 commit 7665cb5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions command/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type buildOptions struct {
tags opts.ListOpts
labels opts.ListOpts
buildArgs opts.ListOpts
extraHosts opts.ListOpts
ulimits *opts.UlimitOpt
memory string
memorySwap string
Expand Down Expand Up @@ -65,10 +66,11 @@ type buildOptions struct {
func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command {
ulimits := make(map[string]*units.Ulimit)
options := buildOptions{
tags: opts.NewListOpts(validateTag),
buildArgs: opts.NewListOpts(opts.ValidateEnv),
ulimits: opts.NewUlimitOpt(&ulimits),
labels: opts.NewListOpts(opts.ValidateEnv),
tags: opts.NewListOpts(validateTag),
buildArgs: opts.NewListOpts(opts.ValidateEnv),
ulimits: opts.NewUlimitOpt(&ulimits),
labels: opts.NewListOpts(opts.ValidateEnv),
extraHosts: opts.NewListOpts(opts.ValidateExtraHost),
}

cmd := &cobra.Command{
Expand Down Expand Up @@ -108,6 +110,7 @@ func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command {
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.SetAnnotation("network", "version", []string{"1.25"})
flags.Var(&options.extraHosts, "add-host", "Add a custom host-to-IP mapping (host:ip)")

command.AddTrustVerificationFlags(flags)

Expand Down Expand Up @@ -301,6 +304,7 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
SecurityOpt: options.securityOpt,
NetworkMode: options.networkMode,
Squash: options.squash,
ExtraHosts: options.extraHosts.GetAll(),
}

response, err := dockerCli.Client().ImageBuild(ctx, body, buildOptions)
Expand Down

0 comments on commit 7665cb5

Please sign in to comment.