For Fly Launch apps: Learn how to create a new app with volumes or add a volume to your app.
fly volumes command.
Fly Volumes are local persistent storage for Fly Machines. Learn how Fly Volumes work.
Note:
fly volumes is aliased to fly volume and fly vol.Access a volume
Access and write to a volume on a Machine just like a regular directory. For Machines managed with Fly Launch, thedestination under [mounts] in fly.toml is the path for the mounted volumes.
For unmanaged Machines, you specify the mount path when you add a volume to a cloned Machine or create a Machine and attach a volume.
Create a volume
Create a Fly Volume:--region option to set a region, or select a region when prompted.
Use the --count option to create more than one volume.
Use the --snapshot-retention option to change the number of days we retain snapshots (default is 5 days).
Use the --scheduled-snapshots=false option to disable automatic daily snapshots.
For more options, refer to the fly volumes create docs or run fly volumes create --help.
Extend a volume
You can make a volume bigger using thefly volume extend command. Note that you can extend (increase) a volume’s size, but you can’t make a volume smaller.
You can also configure a volume to extend automatically after a certain threshold using the Machines API or in the [mounts] section of your app’s fly.toml file.
-
Run
fly volumes listand copy the ID of the volume to extend. -
Extend the volume size:
-
(Optional) Check the new volume size in the Machine’s file system:
Example output:In the preceding example, the volume is mounted under
/storageand has been resized to from 1GB to 2GB. Thedfcommand shows disk space in 1K blocks by default. Use the-hflag to return a more human-readable format.
fly volumes extend docs or run fly volumes extend --help.
Create a copy of a volume (Fork a volume)
Create an exact copy of a volume, including its data. By default, we place the new volume on a separate physical host in the same region. Use the--region option to fork the volume into another region.
Important: After you fork a volume, the new volume is independent of the source volume. The new volume and the source volume do not continue to sync.
-
Run
fly volumes listand copy the ID of the volume to fork. -
Fork the volume:
Example output:
-
(Optional) Use
fly scale countto create a new Machine that picks up the unattached volume, or attach the volume to a new Machine by cloning with the following command:
fly volumes fork docs or run fly volumes fork --help.
A detailed guide to volume forking is also available.
Add a volume to an unmanaged Machine
For Machines that aren’t managed with Fly Launch (fly.toml and fly deploy), you can create a volume and attach it when you clone a Machine. You can also clone a Machine with a volume to get a new Machine with an empty volume.
-
Create the volume in the same region as your app. For example:
-
Clone one of your app’s Machines (with no volume) and attach the volume you just created:
destination-mount-pathis the directory where the volume should be mounted on the file system. Note that you can’t mount a volume with adestination-mount-pathof/, since/is used for the root file system. For example: - Repeat the preceding steps as needed to create more Machines with volumes.
-
Confirm that the volume is attached to a Machine with
fly machine listorfly volumes list. -
(Optional) Destroy the Machine used to create the clone:
Clone a Machine with a volume
Clone a Machine with a volume to create a new Machine in the same region with an empty volume. Use the-r option to clone the Machine into a different region.
-
Run
fly statusand copy the Machine ID of the Machine to clone. -
Clone the Machine:
-
List volumes to check the result:
Example output showing two volumes with attached Machines:
Note:
fly machine clone doesn’t write data into the new volume.fly machine clone docs or run fly machine clone --help.
Destroy a volume
- List volumes and find the ID for the one you want to destroy:
- Destroy the volume using its ID:
fly volumes destroy docs or run fly volumes destroy --help.
Volumes attached to Machines
Volumes attached to Machines can’t be destroyed. You can check which Machine (if any) a volume is attached to by running fly volumes list First, stop and destroy the Machine, then the unattached volume can be destroyed.
If you’re replacing the Machine, use fly scale count or fly machine clone to launch a new one. This will create and mount a fresh volume based on your fly.toml config.
To stop using volumes entirely, remove any [mounts] from fly.toml and redeploy. The Machine will be replaced without the volumes. After redeploying, you can destroy the volumes.
Note: Snapshots taken before deletion may still be restorable for a limited time, provided you have the volume ID (default retention is 5 days).
Restore a deleted volume
You can restore data from a deleted volume using a volume snapshot. At this time, you can only retrieve a deleted volume’s ID for 24 hours after deletion. If you already have the volume ID, then you can still use it to access the volume’s snapshots within the snapshot retention period. The default snapshot retention period is 5 days. Learn how to set or change the snapshot retention period.-
Run
fly volumes list --alland copy the ID of the deleted volume. -
List the volume’s snapshots and copy the ID of the snapshot to restore:
Example output:
-
Restore from the volume snapshot into a new volume of equal or greater size:
Example output:
fly volumes snapshots docs or run fly volumes snapshots --help.