image_load.go 818 B

12345678910111213141516171819202122232425262728293031
  1. package client // import "github.com/docker/docker/client"
  2. import (
  3. "context"
  4. "io"
  5. "net/http"
  6. "net/url"
  7. "github.com/docker/docker/api/types"
  8. )
  9. // ImageLoad loads an image in the docker host from the client host.
  10. // It's up to the caller to close the io.ReadCloser in the
  11. // ImageLoadResponse returned by this function.
  12. func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error) {
  13. v := url.Values{}
  14. v.Set("quiet", "0")
  15. if quiet {
  16. v.Set("quiet", "1")
  17. }
  18. resp, err := cli.postRaw(ctx, "/images/load", v, input, http.Header{
  19. "Content-Type": {"application/x-tar"},
  20. })
  21. if err != nil {
  22. return types.ImageLoadResponse{}, err
  23. }
  24. return types.ImageLoadResponse{
  25. Body: resp.body,
  26. JSON: resp.header.Get("Content-Type") == "application/json",
  27. }, nil
  28. }