0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Docker Composeを使用したAzuriteエミュレータの導入方法

0
Last updated at Posted at 2026-07-13

Azuriteエミュレータとは

以下公式ドキュメントより引用。

Azurite オープンソース エミュレーターは、クラウドベースのアプリケーションをテストするための無料のローカル環境を提供します。 アプリケーションのローカルでの動作に問題がなければ、クラウドで Azure Storage アカウントを使用するように切り替えます。

Azure Storageを使うアプリケーションの開発を行う中で、ローカル環境で動作確認を行いたい場合があると思います。
でもローカルから開発環境のAzureクラウドには接続できない…。そんな時にAzuriteエミュレータを使用すればAzure Storage関連の処理部分の検証ができます。
今回はDocker Composeを使用してAzuriteエミュレータを導入する方法を記します。

筆者の環境

  • WSL:2.7.10.0
  • Ubuntu:24.04 LTS
  • Docker Engine:29.6.1
  • Docker Compose:5.3.0

Azuriteのセットアップ

compose.yamlの作成

公式が出しているazuriteイメージからコンテナを作成するようcompose.yamlに記載します。
既存のネットワークに接続したい場合はnetworks設定を、ホスト側ですでにポートが使用されている(競合している)場合はportsおよびcommand内のポート指定を適宜変更してください。

compose.yaml
services:
  azurite:
    image: mcr.microsoft.com/azure-storage/azurite:latest
    container_name: azurite
    command: "azurite --blobHost 0.0.0.0 --blobPort 10000 --queueHost 0.0.0.0 --queuePort 10001 --tableHost 0.0.0.0 --tablePort 10002 -l /data --debug /data/debug.log --skipApiVersionCheck"
    ports:
      - "10000:10000"  # Blob service
      - "10001:10001"  # Queue service
      - "10002:10002"  # Table service
    volumes:
      - azurite-data:/data
    networks:
      - default

volumes:
  azurite-data:

コンテナ起動

コマンド

docker compose up -d

実行結果

[+] up 14/14
 ✔ Image mcr.microsoft.com/azure-storage/azurite:latest Pulled                                                     17.2s
 ✔ Network azurite_network                              Created                                                     0.0s
 ✔ Volume azurite_azurite-data                          Created                                                     0.0s
 ✔ Container azurite                                    Started                                                     0.6s

コンテナの起動確認

コマンド

docker compose ps

実行結果

NAME      IMAGE                                            COMMAND                  SERVICE   CREATED         STATUS         PORTS
azurite   mcr.microsoft.com/azure-storage/azurite:latest   "docker-entrypoint.s…"   azurite   3 minutes ago   Up 3 minutes   0.0.0.0:10000-10002->10000-10002/tcp, [::]:10000-10002->10000-10002/tcp

動作確認

PythonスクリプトでAzuriteへの接続方法&動作の確認。

筆者の環境

あくまで動作確認用なので参考までに。

  • Python:3.12
  • uv:0.11.28
  • azure-storage-blob:12.30.0

Pythonスクリプト

upload_to_azurite.py
from azure.storage.blob import BlobServiceClient
from azure.core.exceptions import ResourceExistsError

# 設定
CONNECTION_STRING = "UseDevelopmentStorage=true"
CONTAINER_NAME = "test-container"
BLOB_NAME = "example.txt"
DATA = "Hello, Azurite!"

def upload_to_azurite():
    try:
        # BlobServiceClientの作成
        blob_service_client = BlobServiceClient.from_connection_string(CONNECTION_STRING)
        container_client = blob_service_client.get_container_client(CONTAINER_NAME)

        # コンテナの存在チェック
        if not container_client.exists():
            print(f"コンテナ '{CONTAINER_NAME}' が存在しません。作成を開始します...")
            container_client.create_container()
            print(f"コンテナ '{CONTAINER_NAME}' を作成しました。")
        else:
            print(f"コンテナ '{CONTAINER_NAME}' は既に存在します。")

        # データのアップロード
        blob_client = container_client.get_blob_client(BLOB_NAME)
        blob_client.upload_blob(DATA, overwrite=True)
        
        print(f"アップロード成功: {BLOB_NAME}")

    except Exception as e:
        print(f"エラーが発生しました: {e}")

if __name__ == "__main__":
    upload_to_azurite()

補足:接続文字列について

ポート番号やAccountNameAccountKeyをデフォルトから変更していない場合はUseDevelopmentStorage=trueを設定すればAzuriteに接続できます。(公式参照

ライブラリのインストール

動作確認のため、azure-storage-blobは必要。
インストール方法は任意。

# 例
uv add azure-storage-blob

Pythonスクリプトの実行

初回実行結果

コンテナ 'test-container' が存在しません。作成を開始します...
コンテナ 'test-container' を作成しました。
アップロード成功: example.txt

2回目実行結果

コンテナ 'test-container' は既に存在します。
アップロード成功: example.txt

おまけ

Azure CLIを使用してAzuriteエミュレータに対して操作を行うこともできます。

# コンテナ内のBlob一覧を取得
az storage blob list \
  --container-name test-container \
  --connection-string "UseDevelopmentStorage=true" \
  --output table

実行結果

Name         Blob Type    Blob Tier    Length    Content Type              Last Modified              Snapshot
-----------  -----------  -----------  --------  ------------------------  -------------------------  ----------
example.txt  BlockBlob    Hot          15        application/octet-stream  2026-07-08T05:54:09+00:00
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?