2018-02-05 16:05:59 -05:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2016-09-06 14:46:37 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"net/url"
|
2017-09-13 15:49:04 -04:00
|
|
|
"strings"
|
2016-09-06 14:46:37 -04:00
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2017-01-25 19:54:18 -05:00
|
|
|
"github.com/docker/distribution/reference"
|
2016-09-06 14:46:37 -04:00
|
|
|
"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) {
|
2017-01-25 19:54:18 -05:00
|
|
|
ref, err := reference.ParseNormalizedNamed(parentReference)
|
2016-09-06 14:46:37 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
query := url.Values{}
|
2017-01-25 19:54:18 -05:00
|
|
|
query.Set("fromImage", reference.FamiliarName(ref))
|
|
|
|
query.Set("tag", getAPITagFromNamedRef(ref))
|
2017-09-13 15:49:04 -04:00
|
|
|
if options.Platform != "" {
|
|
|
|
query.Set("platform", strings.ToLower(options.Platform))
|
|
|
|
}
|
|
|
|
resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth)
|
2016-09-06 14:46:37 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp.body, nil
|
|
|
|
}
|
|
|
|
|
2017-09-13 15:49:04 -04:00
|
|
|
func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, registryAuth string) (serverResponse, error) {
|
2016-09-06 14:46:37 -04:00
|
|
|
headers := map[string][]string{"X-Registry-Auth": {registryAuth}}
|
|
|
|
return cli.post(ctx, "/images/create", query, nil, headers)
|
|
|
|
}
|