To remove a volume from a Droplet, you can either detach the volume or delete the volume.
- Detaching a volume removes the volume from its current Droplet. You can attach the volume and all of its contents to a different Droplet as needed.
- Deleting a volume permanently destroys the volume and its contents. This action cannot be reversed.
Delete a Volume Using Automation
Before deleting a volume, unmount it to prevent data loss.
How to Delete a Volume Using the DigitalOcean CLI
- Install
doctl
, the official DigitalOcean CLI.
- Create a personal access token and save it for use with
doctl
.
- Use the token to grant
doctl
access to your DigitalOcean account.
- Finally, run
doctl compute volume delete
. Basic usage looks like this, but you can read the usage docs for more details:
doctl compute volume delete <volume-id> [flags]
The following example deletes a volume with the UUID f81d4fae-7dec-11d0-a765-00a0c91e6bf6
:
doctl compute volume delete f81d4fae-7dec-11d0-a765-00a0c91e6bf6
How to Delete a Volume Using the DigitalOcean API
- Create a personal access token and save it for use with the API.
- Send a DELETE request to
https://api.digitalocean.com/v2/volumes/{volume_id}
.
cURL
Using cURL:
curl -X DELETE \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
"https://api.digitalocean.com/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51"
Go
Using Godo, the official DigitalOcean API client for Go:
import (
"context"
"os"
"github.com/digitalocean/godo"
)
func main() {
token := os.Getenv("DIGITALOCEAN_TOKEN")
client := godo.NewFromToken(token)
ctx := context.TODO()
_, err := client.Storage.DeleteVolume(ctx, "7724db7c-e098-11e5-b522-000f53304e51")
}
Ruby
Using DropletKit, the official DigitalOcean API client for Ruby:
require 'droplet_kit'
token = ENV['DIGITALOCEAN_TOKEN']
client = DropletKit::Client.new(access_token: token)
client.volumes.delete(id: '7724db7c-e098-11e5-b522-000f53304e51')
Python
Using PyDo, the official DigitalOcean API client for Python:
import os
from pydo import Client
client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
resp = client.volumes.delete(volume_id="7724db7c")
Delete a Volume Using the Control Panel
Before deleting a volume, unmount it to prevent data loss.
You can delete a volume from the volume’s More menu, which is available on the account-level Volumes page.
When you select Delete, a window to confirm the deletion opens.
When you delete a volume, the volume and its contents are deleted. This action is irreversible.
Click Confirm to delete the volume.