code: func (b *Builder) build(source builder.Source, dockerfile *parser.Result) (*builder.Result, error) {
  	defer b.imageSources.Unmount()
  
  	stages, metaArgs, err := instructions.Parse(dockerfile.AST)
  	if err != nil {
  		if instructions.IsUnknownInstruction(err) {
  			buildsFailed.WithValues(metricsUnknownInstructionError).Inc()
  		}
  		return nil, errdefs.InvalidParameter(err)
  	}
  	if b.options.Target != "" {
  		targetIx, found := instructions.HasStage(stages, b.options.Target)
  		if !found {
  			buildsFailed.WithValues(metricsBuildTargetNotReachableError).Inc()
  			return nil, errdefs.InvalidParameter(errors.Errorf("failed to reach build target %s in Dockerfile", b.options.Target))
  		}
  		stages = stages[:targetIx+1]
  	}
  
  	// Add 'LABEL' command specified by '--label' option to the last stage
  	buildLabelOptions(b.options.Labels, stages)
  
  	dockerfile.PrintWarnings(b.Stderr)
  	dispatchState, err := b.dispatchDockerfileWithCancellation(stages, metaArgs, dockerfile.EscapeToken, source)
  	if err != nil {
  		return nil, err
  	}
  	if dispatchState.imageID == "" {
  		buildsFailed.WithValues(metricsDockerfileEmptyError).Inc()
  		return nil, errors.New("No image was generated. Is your Dockerfile empty?")
  	}
  	return &builder.Result{ImageID: dispatchState.imageID, FromImage: dispatchState.baseImage}, nil
  }
docs: // Build runs the Dockerfile builder by parsing the Dockerfile and executing
  // the instructions from the file.