この記事に沿って、Windows に Podman をセットアップすればよい。
セットアップ時に感じたことをメモしておく。
devcontainer で Azure Functions などの実装を行う際、Azure Storage のエミュレーターとして Azurite を使用します。
version: '3' services: app: (アプリケーションの構成) # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. network_mode: service:storage storage: container_name: azurite image: mcr.microsoft.com/azure-storage/azurite:latest restart: unless-stopped volumes: - storage-data:/data volumes: storage-data:
{ "name": "Node.js & Azurite (Community)", "dockerComposeFile": "docker-compose.yml", "service": "app", "workspaceFolder": "/workspace", "customizations": { "vscode": { "extensions": [ "ms-azuretools.vscode-azurestorage" ] } }, // Azuriteが使用しているポートを転送する // Blob: 10000 // Queue: 10001 // Table: 10002 "forwardPorts": [10000, 10001, 10002], "remoteUser": "node" }
Azure Storage Explorer から devcontainer の Azurite に接続する場合、Azurite の接続文字列を使用します。
ただし http
の接続文字列を使用しましょう。 https
では繋がりません。
Azure CLI を開発環境で使用する場合、Windows や WSL2 の Ubuntu にインストールして使っていましたが、devcontainer にしちゃうのが便利だなと感じてきました。
devcontainer 用のディレクトリを作成し、Visual Studio Code で開きます。
$ mkdir az-profile-development
$ code az-profile-development
Command Palette > Dev Containers: Add Dev Container Configuration Files...
> Azure CLI
を選びます。
.devcontainer/devcontainer.json
はこうなります。
{ "name": "Azure CLI", "dockerFile": "Dockerfile", // Configure tool-specific properties. "customizations": { // Configure properties specific to VS Code. "vscode": { // Add the IDs of extensions you want installed when the container is created. "extensions": [ "ms-vscode.azurecli" ] } }, // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. // "postCreateCommand": "az --version", // Uncomment when using a ptrace-based debugger like C++, Go, and Rust // "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], // Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "vscode" }
devcontainer 定義を作成すると Reopen in Container
がポップアップされるため、クリックします。
az login
の実行コンテナーを起動したばかりの時は、Azure CLI はどのアカウントにもログインしていません。
VSCode のターミナルでコンテナー内のシェルを起動して、コマンドで確認します。
$ az account list -o table Please run "az login" to access your accounts.
az login
でアカウントへのログインを行います。
Azure にログインしたあとは目的のサブスクリプションに接続し、CLI を実行していきます。
この方法であれば、ローカル環境に Azure CLI をインストールする必要がなくなります。
また、プロファイルごとにディレクトリと devcontainer 定義を作成すれば、アカウントの使い分けを行うこともできるのが便利です。
(追記)
Dockerイメージがプロファイルごとに増えるのはちょっと気になるけど、まぁ自分の場合は同時3つくらいなので許容範囲ということで。
※自分の環境では【1.99GB】のコンテナーイメージになりました