2016-09-06 18:46:37 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ImageRemove removes an image from the docker host.
|
2016-11-10 16:27:56 +00:00
|
|
|
func (cli *Client) ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
|
2016-09-06 18:46:37 +00:00
|
|
|
query := url.Values{}
|
|
|
|
|
|
|
|
if options.Force {
|
|
|
|
query.Set("force", "1")
|
|
|
|
}
|
|
|
|
if !options.PruneChildren {
|
|
|
|
query.Set("noprune", "1")
|
|
|
|
}
|
|
|
|
|
2017-09-08 16:04:34 +00:00
|
|
|
var dels []types.ImageDeleteResponseItem
|
2016-09-06 18:46:37 +00:00
|
|
|
resp, err := cli.delete(ctx, "/images/"+imageID, query, nil)
|
|
|
|
if err != nil {
|
2017-09-08 16:04:34 +00:00
|
|
|
return dels, wrapResponseError(err, resp, "image", imageID)
|
2016-09-06 18:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = json.NewDecoder(resp.body).Decode(&dels)
|
|
|
|
ensureReaderClosed(resp)
|
|
|
|
return dels, err
|
|
|
|
}
|