github.com/rawahars/moby@v24.0.4+incompatible/client/image_create.go (about)

     1  package client // import "github.com/docker/docker/client"
     2  
     3  import (
     4  	"context"
     5  	"io"
     6  	"net/url"
     7  	"strings"
     8  
     9  	"github.com/docker/distribution/reference"
    10  	"github.com/docker/docker/api/types"
    11  	"github.com/docker/docker/api/types/registry"
    12  )
    13  
    14  // ImageCreate creates a new image based on 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{registry.AuthHeader: {registryAuth}}
    37  	return cli.post(ctx, "/images/create", query, nil, headers)
    38  }