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.
Prerequisites
Before you begin, ensure you have:
- An Azure subscription. If you don't have one, create a free account before you begin.
- A storage account. If you don't have one, see Create a storage account.
Using the Azure portal
The Azure portal provides a user-friendly graphical interface for managing your Azure resources, including creating blob containers.
- Navigate to your storage account in the Azure portal.
- In the left-hand menu, under Data storage, select Containers.
- Select + Container from the top menu.
- 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.
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.
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:
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:
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}")
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.