client/image_create.go
7c36a1af
 package client
 
 import (
 	"io"
 	"net/url"
d98ecf2d
 	"strings"
7c36a1af
 
 	"golang.org/x/net/context"
 
3a127939
 	"github.com/docker/distribution/reference"
7c36a1af
 	"github.com/docker/docker/api/types"
 )
 
 // ImageCreate creates a new image based in the parent options.
 // It returns the JSON content in the response body.
 func (cli *Client) ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) {
3a127939
 	ref, err := reference.ParseNormalizedNamed(parentReference)
7c36a1af
 	if err != nil {
 		return nil, err
 	}
 
 	query := url.Values{}
3a127939
 	query.Set("fromImage", reference.FamiliarName(ref))
 	query.Set("tag", getAPITagFromNamedRef(ref))
d98ecf2d
 	if options.Platform != "" {
 		query.Set("platform", strings.ToLower(options.Platform))
 	}
 	resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth)
7c36a1af
 	if err != nil {
 		return nil, err
 	}
 	return resp.body, nil
 }
 
d98ecf2d
 func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, registryAuth string) (serverResponse, error) {
7c36a1af
 	headers := map[string][]string{"X-Registry-Auth": {registryAuth}}
 	return cli.post(ctx, "/images/create", query, nil, headers)
 }