2018-02-05 21:05:59 +00:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2016-09-06 18:46:37 +00:00
|
|
|
|
|
|
|
import (
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2016-09-06 18:46:37 +00:00
|
|
|
"io"
|
2023-07-10 14:44:59 +00:00
|
|
|
"net/http"
|
2016-09-06 18:46:37 +00:00
|
|
|
"net/url"
|
2017-09-13 19:49:04 +00:00
|
|
|
"strings"
|
2016-09-06 18:46:37 +00:00
|
|
|
|
2023-08-30 16:31:46 +00:00
|
|
|
"github.com/distribution/reference"
|
2016-09-06 18:46:37 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
2021-08-26 19:08:38 +00:00
|
|
|
"github.com/docker/docker/api/types/registry"
|
2016-09-06 18:46:37 +00:00
|
|
|
)
|
|
|
|
|
2021-02-16 15:07:44 +00:00
|
|
|
// ImageCreate creates a new image based on the parent options.
|
2016-09-06 18:46:37 +00:00
|
|
|
// 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-26 00:54:18 +00:00
|
|
|
ref, err := reference.ParseNormalizedNamed(parentReference)
|
2016-09-06 18:46:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
query := url.Values{}
|
2017-01-26 00:54:18 +00:00
|
|
|
query.Set("fromImage", reference.FamiliarName(ref))
|
|
|
|
query.Set("tag", getAPITagFromNamedRef(ref))
|
2017-09-13 19:49:04 +00:00
|
|
|
if options.Platform != "" {
|
|
|
|
query.Set("platform", strings.ToLower(options.Platform))
|
|
|
|
}
|
|
|
|
resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth)
|
2016-09-06 18:46:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp.body, nil
|
|
|
|
}
|
|
|
|
|
2017-09-13 19:49:04 +00:00
|
|
|
func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, registryAuth string) (serverResponse, error) {
|
2023-07-10 14:44:59 +00:00
|
|
|
return cli.post(ctx, "/images/create", query, nil, http.Header{
|
|
|
|
registry.AuthHeader: {registryAuth},
|
|
|
|
})
|
2016-09-06 18:46:37 +00:00
|
|
|
}
|