Create a container in Azure Blob Storage

This article demonstrates how to create a container in Azure Blob Storage using the Azure portal, Azure CLI, PowerShell, and client libraries.

Tip: Containers are the fundamental organizational unit for data in Azure Blob Storage. Think of them like directories in a file system.

Prerequisites

Before you begin, ensure you have:

Using the Azure portal

The Azure portal provides a user-friendly graphical interface for managing your Azure resources, including creating blob containers.

  1. Navigate to your storage account in the Azure portal.
  2. In the left-hand menu, under Data storage, select Containers.
  3. Select + Container from the top menu.
  4. In the Create container dialog:
    • Enter a unique name for your container. Container names must be lowercase letters and numbers, start with a letter, and be between 3 and 63 characters long.
    • Choose a public access level (e.g., Private, Blob, Container). For most scenarios, Private is recommended.
    • Click Create.
Note: Container names are case-insensitive when referenced via the REST API, but they are stored as they are presented.

Using the Azure CLI

The Azure CLI is a command-line tool for managing Azure resources. You can use it to create containers with a single command.

Azure CLI
az storage container create \
  --name mycontainer \
  --account-name mystorageaccount \
  --auth-mode login 

Replace mycontainer with your desired container name and mystorageaccount with your storage account name.

Using Azure PowerShell

Azure PowerShell provides cmdlets for managing Azure resources. Here's how to create a container:

Azure PowerShell
New-AzStorageContainer -Name "mycontainer" -Context (Get-AzStorageAccount -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount").Context 

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

Using Client Libraries (Python Example)

You can programmatically create containers using Azure Storage client libraries. Here's an example using Python:

Python
from azure.storage.blob import BlobServiceClient

connection_string = "YOUR_CONNECTION_STRING" # Replace with your actual connection string
container_name = "my-new-container"

try:
    blob_service_client = BlobServiceClient.from_connection_string(connection_string)
    container_client = blob_service_client.create_container(container_name)
    print(f"Container '{container_name}' created successfully.")
except Exception as e:
    print(f"An error occurred: {e}")
Important: Ensure you replace YOUR_CONNECTION_STRING with your actual Azure Storage connection string. You can find this in the Azure portal under your storage account's "Access keys" section.

Next Steps