github.com/tonistiigi/docker@v0.10.1-0.20240229224939-974013b0dc6a/client/volume_remove.go (about)

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