2016-09-06 14:46:37 -04: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 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)
|
|
|
|
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)
|
|
|
|
ensureReaderClosed(resp)
|
|
|
|
return dels, err
|
|
|
|
}
|