Azure Docs

List Containers in Azure Blob Storage

This document explains how to list containers within your Azure Storage account using various methods, including the Azure Portal, Azure CLI, PowerShell, and the Azure Storage SDKs.

Prerequisites

Method 1: Using the Azure Portal

The Azure Portal provides a user-friendly interface for managing your storage resources.

  1. Sign in to the Azure Portal.
  2. Navigate to your Storage Account. You can find it by searching for "Storage accounts" in the search bar.
  3. In the storage account menu, under "Data storage", select "Containers".
  4. You will see a list of all containers within this storage account. You can also create new containers, delete existing ones, and manage their settings from this view.

Method 2: Using the Azure CLI

The Azure Command-Line Interface (CLI) is a powerful tool for managing Azure resources from your terminal.

First, ensure you have the Azure CLI installed and logged in:

az login

Then, use the following command to list containers:

az storage container list --account-name  --query "[].name" -o tsv

Replace <your-storage-account-name> with the name of your storage account.

Method 3: Using Azure PowerShell

Azure PowerShell offers cmdlets for managing Azure services.

First, connect to your Azure account:

Connect-AzAccount

Then, use the following command to list containers:

Get-AzStorageContainer -Context (Get-AzStorageAccount -ResourceGroupName  -Name ).Context | Select-Object -ExpandProperty Name

Replace <your-resource-group-name> and <your-storage-account-name> accordingly.

Method 4: Using Azure SDKs (Example: Python)

The Azure SDKs allow you to programmatically interact with Azure services.

Install the Azure Storage Blob SDK for Python:

pip install azure-storage-blob

Here's a Python example:


from azure.storage.blob import BlobServiceClient

# Replace with your actual connection string
connection_string = "YOUR_AZURE_STORAGE_CONNECTION_STRING"
blob_service_client = BlobServiceClient.from_connection_string(connection_string)

print("Containers:")
for container in blob_service_client.list_containers():
    print(f"- {container.name}")
            
Note: It's recommended to use Azure Key Vault or managed identities for securely managing connection strings in production environments.

Understanding Container Properties

When listing containers, you might be interested in various properties, such as:

Property Description
name The name of the container.
creation_time The date and time the container was created.
lease_status The status of the container's lease (locked or unlocked).
lease_state The state of the container's lease (available, leased, expired, breaking).
public_access Indicates if anonymous public read access is enabled for blobs or containers.

Next Steps

After listing your containers, you can proceed to: