Azure Docs

Delete a container

This document explains how to delete an Azure Storage container. Deleting a container also deletes all blobs contained within it. This action is irreversible.

Important: Once a container is deleted, all its contents are permanently lost. Ensure you have backups or are certain you no longer need the data before proceeding.

Prerequisites

Methods to Delete a Container

1. Using the Azure portal

  1. Navigate to your storage account in the Azure portal.
  2. In the left-hand navigation pane, under "Data storage", select "Containers".
  3. Locate the container you wish to delete.
  4. Select the container by clicking its name.
  5. In the container's blade, click the "Delete" button at the top.
  6. A confirmation dialog will appear. Type the name of the container to confirm deletion and click "Delete".

2. Using Azure CLI

Use the az storage container delete command.


az storage container delete --name mycontainer --account-name mystorageaccount --auth-mode login
            

Replace mycontainer with the name of your container and mystorageaccount with your storage account name. The --auth-mode login uses your Azure AD credentials.

3. Using Azure PowerShell

Use the Remove-AzStorageContainer cmdlet.


Remove-AzStorageContainer -Name "mycontainer" -Context (Get-AzStorageAccount -ResourceGroupName "myresourcegroup" -Name "mystorageaccount").Context
            

Replace mycontainer, myresourcegroup, and mystorageaccount with your specific values.

4. Using .NET SDK

You can delete a container programmatically using the Azure Storage client libraries.


using Azure.Storage.Blobs;
using Azure.Identity;

// ...

string accountName = "mystorageaccount";
string containerName = "mycontainer";

// Construct the blob service client with Azure AD authentication
BlobServiceClient blobServiceClient = new BlobServiceClient(
    new Uri($"https://{accountName}.blob.core.windows.net"),
    new DefaultAzureCredential());

// Get a client that references the container
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);

// Delete the container
await containerClient.DeleteAsync();

Console.WriteLine($"Container '{containerName}' deleted successfully.");
            
Note: Ensure you have installed the necessary Azure.Storage.Blobs NuGet package and configured your authentication (e.g., via environment variables, Managed Identity, or Azure CLI login).

5. Using REST API

You can use the Blob Service REST API to delete a container.


DELETE https://mystorageaccount.blob.core.windows.net/mycontainer?restype=container HTTP/1.1
x-ms-version: 2019-02-02
Authorization: SharedKey mystorageaccount:YourAccessKey
Date: Mon, 27 Jul 2024 10:00:00 GMT
Content-Length: 0
            

Replace mystorageaccount, mycontainer, and YourAccessKey with your actual details. For authentication, you can use Shared Key or Azure AD.

Considerations

Tip: For scripting or automation, using Azure CLI, PowerShell, or the client libraries is recommended over manual portal deletion.