title: How to use io reader client
body: <p>I would like to copy a zipped file from host machine to a container using go code running inside a container. The setup has go code running in a container with docker.sock mounted. The idea is to copy zip file from host machine to the container that runs go code. The path parameter is on the host machine. On host machine command line looks like this</p>
  <pre><code>docker cp hostFile.zip myContainer:/tmp/
  </code></pre>
  <p>The documentation for <a href="https://pkg.go.dev/github.com/moby/docker/client#Client.CopyToContainer" rel="nofollow noreferrer">docker-client CopyToContainer</a> looks</p>
  <pre><code>func (cli *Client) CopyToContainer(ctx context.Context, containerID, dstPath string, content io.Reader, options types.CopyToContainerOptions) error
  </code></pre>
  <p>How to create <code>content io.Reader</code> argument ?</p>
  <pre><code>cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
  if err != nil {
      panic(err)
  }
  
  // TODO
  // reader := io.Reader()
  // reader := file.NewReader()
  // tar.NewReader()
  
  cli.CopyToContainer(context.Background(), containerID, dst, reader, types.CopyToContainerOptions{
      AllowOverwriteDirWithFile: true,
      CopyUIDGID:                true,
  })
  </code></pre>