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 (
|
2018-04-19 18:30:59 -04:00
|
|
|
"context"
|
2016-09-06 14:46:37 -04:00
|
|
|
"encoding/json"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ImageRemove removes an image from the docker host.
|
2016-11-10 11:27:56 -05:00
|
|
|
func (cli *Client) ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
|
2016-09-06 14:46:37 -04:00
|
|
|
query := url.Values{}
|
|
|
|
|
|
|
|
if options.Force {
|
|
|
|
query.Set("force", "1")
|
|
|
|
}
|
|
|
|
if !options.PruneChildren {
|
|
|
|
query.Set("noprune", "1")
|
|
|
|
}
|
|
|
|
|
2017-09-08 12:04:34 -04:00
|
|
|
var dels []types.ImageDeleteResponseItem
|
2016-09-06 14:46:37 -04:00
|
|
|
resp, err := cli.delete(ctx, "/images/"+imageID, query, nil)
|
2019-02-11 07:26:12 -05:00
|
|
|
defer ensureReaderClosed(resp)
|
2016-09-06 14:46:37 -04:00
|
|
|
if err != nil {
|
2017-09-08 12:04:34 -04:00
|
|
|
return dels, wrapResponseError(err, resp, "image", imageID)
|
2016-09-06 14:46:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
err = json.NewDecoder(resp.body).Decode(&dels)
|
|
|
|
return dels, err
|
|
|
|
}
|