Azure Documentation

Your guide to Microsoft Azure services

Manage Azure Storage Containers

This article provides a comprehensive guide on managing containers in Azure Blob Storage. Containers are essential for organizing and storing your blob data.

What is an Azure Storage Container?

A container is a logical grouping of blobs. All blobs in a container must have a unique name within that container. You can think of a container as a directory in a file system.

Key Features of Containers:

  • Unique Names: Container names must be unique within a storage account.
  • Access Control: You can define access policies at the container level.
  • Hierarchical Namespace: Supports hierarchical structuring of data, especially with Azure Data Lake Storage Gen2.
  • Metadata: Containers can have associated metadata.

Creating a Container

Containers can be created using Azure portal, Azure CLI, PowerShell, or programmatically using SDKs.

Using Azure CLI:

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

Using Azure PowerShell:

New-AzStorageContainer -Name "mycontainer" -Context $ctx
Note: Container names must start with a letter or number, and can contain only letters, numbers, and the hyphen (-) character. The name must be between 3 and 63 characters long.

Listing Containers

To view all containers within a storage account:

Using Azure CLI:

az storage container list \
    --account-name mystorageaccount \
    --auth-mode login \
    --output table

Using Azure PowerShell:

Get-AzStorageContainer -Context $ctx

Deleting a Container

You can delete a container and all of its contents. This action is irreversible.

Using Azure CLI:

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

Using Azure PowerShell:

Remove-AzStorageContainer -Name "mycontainer" -Context $ctx
Tip: Before deleting, ensure you have backed up any critical data within the container.

Container Properties and Access Levels

Containers have several properties that you can manage, including their access level.

Access Levels:

  • Private: Access to containers and blobs is restricted to account owners.
  • Blob: Anonymous public read access for blobs is permitted, but container data is still restricted to account owners.
  • Container: Anonymous public read access for blobs and container metadata is permitted.

You can set or get the access level using Azure CLI:

# Set to private
az storage container set-permission \
    --name mycontainer \
    --account-name mystorageaccount \
    --public-access off \
    --auth-mode login

# Get access level
az storage container show --name mycontainer --account-name mystorageaccount --auth-mode login --query publicAccess

Container Metadata

You can store custom data in the form of metadata on a container. Metadata is a set of name-value pairs.

Setting Metadata:

az storage container metadata update \
    --name mycontainer \
    --account-name mystorageaccount \
    --metadata project=beta \
    --auth-mode login

Getting Metadata:

az storage container metadata show \
    --name mycontainer \
    --account-name mystorageaccount \
    --auth-mode login

Best Practices

  • Organize blobs logically into containers.
  • Use appropriate access control levels for security.
  • Consider using hierarchical namespaces for analytical workloads.
  • Monitor container usage and performance.