Azure CLI Storage Container Documentation

This document provides comprehensive guidance on managing Azure Storage Containers using the Azure Command-Line Interface (CLI).

Azure Blob Storage containers are essential for organizing data in Azure Blob Storage. The Azure CLI offers a powerful and flexible way to create, configure, and manage these containers programmatically.

Key Container Commands

The Azure CLI provides a rich set of commands for container management. Here are some of the most commonly used ones:

az storage container create

Creates a new container.

az storage container create --name MyContainer --account-name mystorageaccount --auth-mode login

az storage container list

Lists containers in a storage account.

az storage container list --account-name mystorageaccount --auth-mode login

az storage container show

Shows the properties of a specific container.

az storage container show --name MyContainer --account-name mystorageaccount --auth-mode login

az storage container delete

Deletes a container.

az storage container delete --name MyContainer --account-name mystorageaccount --auth-mode login

az storage container policy list

Lists access policies for a container.

az storage container policy list --container-name MyContainer --account-name mystorageaccount --auth-mode login

az storage container policy create

Creates a shared access policy for a container.

az storage container policy create --container-name MyContainer --name ReadOnlyPolicy --permissions r --account-name mystorageaccount --auth-mode login

Usage Examples

Creating a Container

To create a new container named my-new-container in your storage account mystorageaccount, you can use the following command. It's recommended to use Azure AD authentication (--auth-mode login) where possible.

az storage container create --name my-new-container --account-name mystorageaccount --auth-mode login

Listing Containers

Retrieve a list of all containers within your storage account:

az storage container list --account-name mystorageaccount --auth-mode login

Setting Container Permissions

Containers can have different public access levels: blob, container, or off (private). To set a container to allow public read access to blobs:

az storage container set-permission --name my-new-container --public-access blob --account-name mystorageaccount --auth-mode login

Common Parameters

Most container commands accept the following common parameters:

Parameter Description Required
--name or -n The name of the storage container. Yes (for specific container operations)
--account-name The name of the storage account. Yes
--auth-mode The authentication mode. Options are login (for Azure AD) or key (for account key). No (defaults to key if not specified and login fails)
--account-key The storage account access key. Use only when --auth-mode key is specified. No
--connection-string A connection string for the storage account. No
--metadata Space-separated key=value pairs for container metadata. No
--public-access Public access level: blob, container, or off. No
Note: Always refer to the official Azure CLI documentation for the most up-to-date command syntax and available parameters.

Related Services and Concepts