Delete a Container
This guide explains how to delete a blob container in Azure Storage. Deleting a container also deletes all the blobs contained within it. This operation is irreversible.
Prerequisites
- An Azure Storage account.
- Permissions to delete containers (e.g., Storage Blob Data Owner role).
- The name of the container you wish to delete.
Methods to Delete a Container
You can delete a container using the Azure portal, Azure CLI, PowerShell, or the Azure Storage SDKs.
Azure CLI
Use the Azure CLI command az storage container delete to remove a container. Replace <container-name> with the name of your container and <storage-account-name> with your storage account name.
az storage container delete \
--name <container-name> \
--account-name <storage-account-name> \
--auth-mode login
For accounts that require a connection string, use:
az storage container delete \
--name <container-name> \
--connection-string <your-connection-string>
You may be prompted to confirm the deletion.
Azure PowerShell
Use the Azure PowerShell cmdlet Remove-AzStorageContainer. Replace <container-name> with your container name and <storage-account-name> with your storage account name.
Remove-AzStorageContainer -Name <container-name> -Context (New-AzStorageContext -StorageAccountName <storage-account-name> -UseSubDomain)
Alternatively, using a connection string:
Remove-AzStorageContainer -Name <container-name> -ConnectionString <your-connection-string>
Azure Portal
- Navigate to your storage account in the Azure portal.
- In the left-hand menu, under Data storage, select Containers.
- Locate the container you wish to delete in the list.
- Click the ellipsis (...) to the right of the container name, and select Delete container.
- In the confirmation dialog, type the name of the container to confirm deletion and click Delete.
Azure Storage SDKs
You can also programmatically delete containers using the Azure Storage SDKs for various languages (e.g., .NET, Java, Python, Node.js).
For example, using the .NET SDK:
// Assuming you have a BlobServiceClient object configured
await blobServiceClient.DeleteContainerAsync(containerName);
Refer to the official Azure documentation for detailed code examples in different languages.
Important Considerations
- Data Loss: Once deleted, a container and its contents cannot be recovered.
- Permissions: Ensure you have the necessary permissions to perform this action.
- Associated Resources: Deleting a container does not affect the storage account itself.
For more information on managing containers, see Create a container.