image_remove.go 661 B

1234567891011121314151617181920212223242526272829303132
  1. package client
  2. import (
  3. "encoding/json"
  4. "net/url"
  5. "github.com/docker/engine-api/types"
  6. "golang.org/x/net/context"
  7. )
  8. // ImageRemove removes an image from the docker host.
  9. func (cli *Client) ImageRemove(ctx context.Context, options types.ImageRemoveOptions) ([]types.ImageDelete, error) {
  10. query := url.Values{}
  11. if options.Force {
  12. query.Set("force", "1")
  13. }
  14. if !options.PruneChildren {
  15. query.Set("noprune", "1")
  16. }
  17. resp, err := cli.delete(ctx, "/images/"+options.ImageID, query, nil)
  18. if err != nil {
  19. return nil, err
  20. }
  21. var dels []types.ImageDelete
  22. err = json.NewDecoder(resp.body).Decode(&dels)
  23. ensureReaderClosed(resp)
  24. return dels, err
  25. }