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
|
|
|
"encoding/json"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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)
|
2019-02-11 12:26:12 +00:00
|
|
|
defer ensureReaderClosed(resp)
|
2016-09-06 18:46:37 +00:00
|
|
|
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)
|
|
|
|
return dels, err
|
|
|
|
}
|