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