Creating Blob Containers in Azure is a straightforward process.
A blob container is a logical grouping of blobs (files) in an Azure Storage account.
Below is a detailed guide on how to create a blob container in Azure.
Method 1: Create a Blob Container using Azure Portal
Step 1: Log in to the Azure Portal
Go to Azure Portal.
Sign in with your Azure account credentials.
Step 2: Navigate to the Storage Account
In the left sidebar, select Storage accounts.
Select the Storage account where you want to create the blob container.
If you don't have one, create a new storage account by clicking + Add and following the prompts.
Step 3: Create the Blob Container
In your selected storage account, scroll down and under the Data storage section, click on Containers.
Click on + Container at the top of the screen.
In the Create container pane:
Name: Enter a unique name for the blob container (e.g.,
mycontainer).Public Access Level:
Private: No public access to the blobs.
Blob: Public read access to blobs only.
Container: Public read and list access to both the blobs and the container.
Click Create.
Your blob container is now created, and you can start uploading blobs (files) into it.
Method 2: Create a Blob Container using Azure CLI
Step 1: Install Azure CLI
If you haven’t already installed Azure CLI, download and install it from the official site: .
Step 2: Log in to Azure CLI
Open your terminal or command prompt and log in using the following command:
xxxxxxxxxx11az loginFollow the prompts to authenticate.
Step 3: Create the Blob Container
Once you're logged in, run the following command to create a blob container:
xxxxxxxxxx41az storage container create \2--name <container-name> \3--account-name <storage-account-name> \4--public-access offReplace
<container-name>with your desired container name (e.g.,mycontainer).Replace
<storage-account-name>with your Azure Storage account name.The
--public-access offoption ensures that the container has no public access.You can change it to
bloborcontainerdepending on the access level you want.
Example
xxxxxxxxxx41az storage container create \2--name mycontainer \3--account-name mystorageacct \4--public-access offMethod 3: Create a Blob Container using Azure PowerShell
Step 1: Install Azure PowerShell
If you haven’t already installed Azure PowerShell, follow the instructions here: Install Azure PowerShell.
Step 2: Log in to Azure
Use the following command to sign in to Azure:
xxxxxxxxxx11Connect-AzAccountStep 3: Create the Blob Container
Use the following PowerShell command to create a blob container:
xxxxxxxxxx81$context = New-AzStorageContext `2-StorageAccountName <storage-account-name> `3-StorageAccountKey <storage-account-key>4
5New-AzStorageContainer `6-Name <container-name> `7-Context $context `8-PublicAccess OffReplace
<storage-account-name>with your storage account name.Replace
<storage-account-key>with your storage account keyYou can get this from the Access keys section of your storage account.
Replace
<container-name>with the desired blob container name.The
-PublicAccess Offoption ensures that no public access is allowed.
Example
xxxxxxxxxx81$context = New-AzStorageContext `2-StorageAccountName mystorageacct `3-StorageAccountKey <storage-account-key>4
5New-AzStorageContainer `6-Name mycontainer `7-Context $context `8-PublicAccess OffMethod 4: Create a Blob Container Using Azure SDKs
If you're developing an application that interacts with Azure Blob Storage, you can use Azure SDKs for languages like Python, .NET, Java, or Node.js.
Example in Python
Install the Azure Blob Storage SDK:
xxxxxxxxxx11pip install azure-storage-blobUse the following Python code to create a container:
xxxxxxxxxx91from azure.storage.blob import BlobServiceClient2# Azure storage account connection string3connection_string = "<your-connection-string>"4# Create BlobServiceClient5blob_service_client = BlobServiceClient.from_connection_string(connection_string)6# Create a container7container_name = "mycontainer"8container_client = blob_service_client.create_container(container_name)9print(f"Container '{container_name}' created successfully.")Replace <your-connection-string> with your actual connection string from the Azure Portal.
Step 5: Upload Files to Your Blob Container
Once you’ve created a blob container, you can start uploading files (blobs) into it using:
Azure Portal
Go to the Containers section.
Open the container you created.
Click Upload and select the file(s) you want to upload.
Azure CLI
xxxxxxxxxx51az storage blob upload \2--container-name <container-name> \3--file <path-to-your-file> \4--name <blob-name> \5--account-name <storage-account-name>PowerShell
xxxxxxxxxx51Set-AzStorageBlobContent `2-Container <container-name> `3-File <path-to-your-file> `4-Blob <blob-name> `5-Context $contextSummary
By following these steps, you can create blob containers in Azure using different methods, whether it's the Azure Portal, CLI, PowerShell, or SDKs.




















Leave a Reply