😸

Azure 向け開発のためのローカルリソース準備

2023/11/05に公開

はじめに

Azure 上で実行するための各種アプリを開発する際、開発作業用としてローカルに代替環境を用意するためのメモ。

開発作業目的でセキュリティの事はあまり考えていないので、格納するデータは注意しましょう。

Azure SQL Database

Azure SQL Database は MS SQL Server なので、 SQL Server のコンテナ版を入れます。

https://learn.microsoft.com/ja-jp/sql/linux/quickstart-install-connect-docker

https://learn.microsoft.com/ja-jp/sql/linux/sql-server-linux-configure-environment-variables

https://learn.microsoft.com/ja-jp/sql/linux/sql-server-linux-docker-container-configure

上記を踏まえて Docker Compose の設定を下記のようにしました。

docker-compose.yml
version: "3"
services:
  mssql:
    image: mcr.microsoft.com/mssql/server:2022-latest
    user: root
    container_name: mssql
    ports:
      - 127.0.0.1:1433:1433
    environment:
      - ACCEPT_EULA=Y
      - MSSQL_SA_PASSWORD=<YourStrong@Passw0rd>
      - MSSQL_PID=Developer
      - MSSQL_LCID=1041
      - MSSQL_COLLATION=Japanese_CI_AS
    volumes:
      - ./db:/var/opt/mssql

"<YourStrong@Passw0rd>" は任意のパスワードを設定します。

"user: root" の設定は下記エラー対策によるものです。

mssql  | SQL Server 2022 will run as non-root by default.
mssql  | This container is running as user mssql.
mssql  | To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
mssql  | /opt/mssql/bin/sqlservr: Error: The system directory [/.system] could not be created. File: LinuxDirectory.cpp:420 [Status: 0xC0000022 Access Denied errno = 0xD(13) Permission denied]

https://github.com/microsoft/mssql-docker/issues/615#issuecomment-755343546

ログインは

Name Value
Server localhost
User name SA
Password MSSQL_SA_PASSWORD で設定したもの

SQL Server の開発版を入れる

別の方法として Windows では SQL Server の開発版を入れる事も可能です。

https://www.microsoft.com/ja-jp/sql-server/sql-server-2022-pricing

Azure Storage

Blob Storage, Queue Storage などをローカルで試すには Azurite を利用します。

https://learn.microsoft.com/ja-jp/azure/storage/common/storage-use-azurite

いくつか方法がありますが、ここでも Docker で。

docker-compose.yml
version: "3"
services:
  azurite:
    image: mcr.microsoft.com/azure-storage/azurite:latest
    container_name: azurite
    ports:
      - 127.0.0.1:10000:10000
      - 127.0.0.1:10001:10001
      - 127.0.0.1:10002:10002
    volumes:
      - ./azurite:/data

Azure Cosmos DB

Cosmos DB もエミュレーターがあります。

https://learn.microsoft.com/ja-jp/azure/cosmos-db/how-to-develop-emulator

Docker Compose ではうまく上げられなかった (docker コマンドであれば問題なかった) ので改めて試します。

Discussion