Use this file to discover all available pages before exploring further.
The volume API manages persistent storage that can be mounted into containers. All methods are on the Docker struct. Options builders live in bollard::query_parameters; model structs live in bollard::models.
use bollard::Docker;use bollard::models::VolumeCreateRequest;use bollard::query_parameters::RemoveVolumeOptionsBuilder;#[tokio::main]async fn main() { let docker = Docker::connect_with_socket_defaults().unwrap(); // 1. Create a named volume let config = VolumeCreateRequest { name: Some(String::from("app-data")), labels: Some( [("env".to_string(), "production".to_string())] .into_iter() .collect(), ), ..Default::default() }; let vol = docker.create_volume(config).await.unwrap(); println!("Created: {} at {}", vol.name, vol.mountpoint); // 2. Inspect it let info = docker.inspect_volume("app-data").await.unwrap(); println!("Labels: {:?}", info.labels); // 3. Remove it (force) let opts = RemoveVolumeOptionsBuilder::default().force(true).build(); docker.remove_volume("app-data", Some(opts)).await.unwrap(); println!("Volume removed");}
Removing a volume deletes all data stored in it permanently. There is no recovery path. Always verify that no containers are using the volume before removal.
When using named volumes with the local driver, you can pass driver options such as type, device, and o (mount options) in driver_opts to create volumes backed by NFS, tmpfs, or other filesystem types.