volume_remove.go 793 B

123456789101112131415161718192021222324252627
  1. package client // import "github.com/docker/docker/client"
  2. import (
  3. "context"
  4. "net/url"
  5. "github.com/docker/docker/api/types/versions"
  6. )
  7. // VolumeRemove removes a volume from the docker host.
  8. func (cli *Client) VolumeRemove(ctx context.Context, volumeID string, force bool) error {
  9. query := url.Values{}
  10. if force {
  11. // Make sure we negotiated (if the client is configured to do so),
  12. // as code below contains API-version specific handling of options.
  13. //
  14. // Normally, version-negotiation (if enabled) would not happen until
  15. // the API request is made.
  16. cli.checkVersion(ctx)
  17. if versions.GreaterThanOrEqualTo(cli.version, "1.25") {
  18. query.Set("force", "1")
  19. }
  20. }
  21. resp, err := cli.delete(ctx, "/volumes/"+volumeID, query, nil)
  22. defer ensureReaderClosed(resp)
  23. return err
  24. }