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