github.com/hms58/moby@v1.13.1/client/image_create.go (about)

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