Delete a container
This guide explains how to delete a container from your Azure Storage account using the Azure portal, Azure CLI, PowerShell, and SDKs.
Important: Deleting a container also deletes all blobs within that container. This operation is irreversible. Ensure you have backups or have extracted necessary data before proceeding.
Prerequisites
- An Azure Storage account.
- Permissions to manage containers within the storage account.
Using the Azure Portal
- Sign in to the Azure portal.
- Navigate to your storage account.
- In the left navigation menu, under Data storage, select Containers.
- Select the container you wish to delete.
- In the container's overview, click the Delete button.
- A confirmation dialog will appear. Type the container name to confirm and click Delete.
Using Azure CLI
Use the az storage container delete command.
az storage container delete --name <container-name> --account-name <storage-account-name> [--auth-mode login] [--connection-string <connection-string>] [--sas-token <sas-token>] [--account-key <account-key>]
Replace <container-name> and <storage-account-name> with your container and storage account names.
Using Azure PowerShell
Use the Remove-AzStorageContainer cmdlet.
Remove-AzStorageContainer -Name <container-name> -Context (New-AzStorageContext -StorageAccountName "<storage-account-name>" -StorageAccountKey "<storage-account-key>")
Alternatively, if you are logged in:
Remove-AzStorageContainer -Name <container-name> -Context $ctx
Replace placeholders with your actual values.
Using .NET SDK
Here's an example using the Azure Blob Storage client library for .NET:
using Azure.Storage.Blobs;
using System;
// Replace with your connection string and container name
string connectionString = "YOUR_AZURE_STORAGE_CONNECTION_STRING";
string containerName = "my-container-to-delete";
try
{
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
await blobServiceClient.DeleteBlobContainerAsync(containerName);
Console.WriteLine($"Container '{containerName}' deleted successfully.");
}
catch (Exception ex)
{
Console.WriteLine($"Error deleting container: {ex.Message}");
}
Considerations
- Irreversibility: Once deleted, the container and its contents cannot be recovered.
- Permissions: Ensure you have the necessary RBAC roles or access keys to perform the delete operation.
- Lease: If a container has an active lease, you must break or release the lease before deleting it.
Warning: Double-check the container name and ensure you are deleting the correct container. Accidental deletion can lead to data loss.