image_create.go 1012 B

12345678910111213141516171819202122232425262728293031323334
  1. package client
  2. import (
  3. "io"
  4. "net/url"
  5. "golang.org/x/net/context"
  6. "github.com/docker/distribution/reference"
  7. "github.com/docker/docker/api/types"
  8. )
  9. // ImageCreate creates a new image based in the parent options.
  10. // It returns the JSON content in the response body.
  11. func (cli *Client) ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) {
  12. ref, err := reference.ParseNormalizedNamed(parentReference)
  13. if err != nil {
  14. return nil, err
  15. }
  16. query := url.Values{}
  17. query.Set("fromImage", reference.FamiliarName(ref))
  18. query.Set("tag", getAPITagFromNamedRef(ref))
  19. resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth)
  20. if err != nil {
  21. return nil, err
  22. }
  23. return resp.body, nil
  24. }
  25. func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, registryAuth string) (serverResponse, error) {
  26. headers := map[string][]string{"X-Registry-Auth": {registryAuth}}
  27. return cli.post(ctx, "/images/create", query, nil, headers)
  28. }