Validated on 16 Dec 2019 • Last edited on 18 Dec 2024
Volumes are network-based block devices that provide additional data storage for Droplets. You can move them between Droplets, create disk images of them, and resize them at any time.
To move a volume between Droplets in the same region, you need to unmount and detach it from its current Droplet, then attach and mount it to the new Droplet.
Between Droplets in the Same Region
Using the Control Panel
Unmount the volume from the current Droplet using the command line, or power down the Droplet. This makes sure the Droplet is not writing to the volume when you move it.
Detach the volume from the current Droplet using the control panel. In the volume’s More menu, choose Detach from Droplet.
Attach the volume to a different Droplet using the control panel. In the volume’s More menu, choose Attach to Droplet., then select the Droplet you want to use.
You can choose any Droplet in the same region. Droplets in other datacenters are visible but cannot be selected.
Mount the volume to make it accessible to the new Droplet’s filesystem. The mount directions are also in the volume’s More menu, under Config instructions.
Using the API or CLI
First, unmount the volume from the current Droplet using the command line, or power down the Droplet. This makes sure the Droplet is not writing to the volume when you move it. Then, detach the volume.
How to Attach a Volume to a Droplet Using the DigitalOcean CLI
# Attach a Volume to a Droplet by IDcurl -X POST \
-H "Content-Type: application/json"\
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN"\
-d '{"type": "attach", "droplet_id": 11612190, "region": "nyc1", "tags":["aninterestingtag"]}'\
"https://api.digitalocean.com/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51/actions"# Remove a Volume from a Droplet by IDcurl -X POST \
-H "Content-Type: application/json"\
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN"\
-d '{"type": "detach", "droplet_id": "11612190", "region": "nyc1"}'\
"https://api.digitalocean.com/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51/actions"# Resize a Volumecurl -X POST \
-H "Content-Type: application/json"\
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN"\
-d '{"type":"resize","size_gigabytes": 100, "region":"nyc1"}'\
"https://api.digitalocean.com/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51/actions"
Go
Using Godo, the official DigitalOcean API client for Go:
import("context""os""github.com/digitalocean/godo")funcmain(){token:=os.Getenv("DIGITALOCEAN_TOKEN")client:=godo.NewFromToken(token)ctx:=context.TODO()// Attach a Volume to a Droplet by IDaction,_,err:=client.StorageActions.Attach(ctx,"7724db7c-e098-11e5-b522-000f53304e51",11612190)// Remove a Volume from a Droplet by ID// action, _, err := client.StorageActions.Detach(ctx, "7724db7c-e098-11e5-b522-000f53304e51")// Resize a Volume// action, _, err := client.StorageActions.Resize(ctx, "7724db7c-e098-11e5-b522-000f53304e51", 100, "nyc1")}
Ruby
Using DropletKit, the official DigitalOcean API client for Ruby:
require'droplet_kit'token=ENV['DIGITALOCEAN_TOKEN']client=DropletKit::Client.new(access_token:token)# Attach a Volume to a Droplet by IDclient.volume_actions.attach(volume_id:'7724db7c-e098-11e5-b522-000f53304e51',droplet_id:11612190,region:'nyc1'# Remove a Volume from a Droplet by ID# client.volume_actions.detach(volume_id:'7724db7c-e098-11e5-b522-000f53304e51', droplet_id: 11612190, region: 'nyc1'
Python
Using PyDo, the official DigitalOcean API client for Python:
Volumes are region-specific resources, meaning you can’t use them with Droplets in different regions. You currently can’t transfer volumes or snapshots of volumes to different regions.