image_create.go 817 B

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