title: docker build in Go client fail on COPY
body: <p>I'm trying to build an image using docker's Go client. Here is the Go program I'm running:</p>
  
  <pre><code>func main() {
      ctx := context.Background()
      cli, err := client.NewEnvClient()
      if err != nil {
          log.Fatal(err, " :unable to init client")
      }
  
      buf := new(bytes.Buffer)
      tw := tar.NewWriter(buf)
      defer tw.Close()
  
      dockerFile := "Dockerfile"
      dockerFileReader, err := os.Open("./Dockerfile")
      if err != nil {
          log.Fatal(err, " :unable to open Dockerfile")
      }
      readDockerFile, err := ioutil.ReadAll(dockerFileReader)
      if err != nil {
          log.Fatal(err, " :unable to read dockerfile")
      }
  
      tarHeader := &amp;tar.Header{
          Name: dockerFile,
          Size: int64(len(readDockerFile)),
      }
      err = tw.WriteHeader(tarHeader)
      if err != nil {
          log.Fatal(err, " :unable to write tar header")
      }
      _, err = tw.Write(readDockerFile)
      if err != nil {
          log.Fatal(err, " :unable to write tar body")
      }
      dockerFileTarReader := bytes.NewReader(buf.Bytes())
  
      imageBuildResponse, err := cli.ImageBuild(
          ctx,
          dockerFileTarReader,
          types.ImageBuildOptions{
              Dockerfile: dockerFile,
              Tags:       []string{"devbuild"},
              Remove:     true})
      if err != nil {
          log.Fatal(err, " :unable to build docker image")
      }
      defer imageBuildResponse.Body.Close()
      _, err = io.Copy(os.Stdout, imageBuildResponse.Body)
      if err != nil {
          log.Fatal(err, " :unable to read image build response")
      }
  }
  </code></pre>
  
  <p>It puts the <code>Dockerfile</code> (located in the current directory) in a <code>tar</code> file and builds an image using <code>cli.ImageBuild</code>. This solution was taken from this <a href="https://stackoverflow.com/questions/38804313/build-docker-image-from-go-code">post</a>, and my <code>Dockerfile</code> looks like this:</p>
  
  <pre><code>FROM alpine:latest
  
  WORKDIR /gopath/src/build
  COPY ./binary_build/ /usr/local/bin/
  </code></pre>
  
  <p>I'm constantly getting the error on the last step:</p>
  
  <pre><code>{"stream":"Step 3/3 : COPY /binary_build/ /usr/local/bin/"}
  {"stream":"\n"}
  {"errorDetail":{"message":"COPY failed: stat /var/lib/docker/tmp/docker-builder389608393/binary_build: no such file or directory"},"error":"COPY failed: stat /var/lib/docker/tmp/docker-builder389608393/binary_build: no such file or directory"}
  </code></pre>
  
  <p>There seems to be similar issue in the past reported <a href="https://github.com/docker/for-mac/issues/1677" rel="nofollow noreferrer">here</a>, but it seems to have been patched. I ran <code>go get github.com/docker/docker@latest</code> and my docker version in <code>go.mod</code> is <code>github.com/docker/docker v1.13.1</code>. The issue still persists.</p>