7d62e40f7e
Since Go 1.7, context is a standard package. Since Go 1.9, everything that is provided by "x/net/context" is a couple of type aliases to types in "context". Many vendored packages still use x/net/context, so vendor entry remains for now. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package client // import "github.com/docker/docker/client"
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/docker/distribution/reference"
|
|
"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) {
|
|
ref, err := reference.ParseNormalizedNamed(parentReference)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
query := url.Values{}
|
|
query.Set("fromImage", reference.FamiliarName(ref))
|
|
query.Set("tag", getAPITagFromNamedRef(ref))
|
|
if options.Platform != "" {
|
|
query.Set("platform", strings.ToLower(options.Platform))
|
|
}
|
|
resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return resp.body, nil
|
|
}
|
|
|
|
func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, registryAuth string) (serverResponse, error) {
|
|
headers := map[string][]string{"X-Registry-Auth": {registryAuth}}
|
|
return cli.post(ctx, "/images/create", query, nil, headers)
|
|
}
|