如何获取默认安装 Azure CLI 的代码空间?

问题描述 投票:0回答:1

我正在尝试构建一个默认安装 Azure CLI 的 Github 代码空间。

在我的 devcontainer.json 文件中,我有 Azure Tools 和 Azure CLI Tools 扩展,我可以从这些扩展访问 Azure。

但是,在我的终端中,我似乎无法访问 az cli。我刚刚收到“bash:az:找不到命令”错误。

我可以通过每次启动新的代码空间时运行此命令来手动安装 Azure CLI。

sudo su root
curl -L https://aka.ms/InstallAzureCli | sudo bash

这是我的 devcontainer.json 文件

{
    "name": ".NET in Codespaces",
    "image": "mcr.microsoft.com/dotnet/sdk:8.0",
    "features": {
        "ghcr.io/devcontainers/features/docker-in-docker:2": {},
        "ghcr.io/devcontainers/features/github-cli:1": {
            "version": "2"
        },
        "ghcr.io/devcontainers/features/powershell:1": {
            "version": "latest"
        },
        "ghcr.io/azure/azure-dev/azd:0": {
            "version": "latest"
        },
        "ghcr.io/devcontainers/features/common-utils:2": {},
        "ghcr.io/devcontainers/features/dotnet:2": {
            "version": "none",
            "dotnetRuntimeVersions": "7.0",
            "aspNetCoreRuntimeVersions": "7.0"
        }
    },
    "customizations": {
        "vscode": {
            "extensions": [
                "ms-vscode.vscode-node-azure-pack",
                "GitHub.copilot",
                "GitHub.vscode-github-actions",
                "ms-dotnettools.vscode-dotnet-runtime",
                "ms-dotnettools.csdevkit",
                "ms-dotnetools.csharp",
                "ms-vscode.azurecli"
            ]
        }
    },
    "forwardPorts": [
        8080,
        8081
    ],
    "postCreateCommand": "cd ./SampleApp && dotnet restore",
    "hostRequirements": {
        "memory": "8gb",
        "cpus": 4
    },
    "remoteEnv": {
        "DOTNET_MULTILEVEL_LOOKUP": "0",
        "TARGET": "net8.0"
    },
    "portsAttributes": {
        "8080": {
            "label": "Weather API",
            "onAutoForward": "notify"
        },
        "8081": {
            "label": "Weather Front End",
            "onAutoForward": "notify"
        }
    }
}

为了让 codespace 每次安装 azure cli,我需要更改什么?

这是我的存储库,如果有帮助的话(我唯一更改的是 devcontainer.json 文件)https://github.com/waiholiu/dotnet-codespace-withazurecli

azure github azure-cli github-codespaces
1个回答
0
投票

看起来您已经解决了这个问题,但与遇到这篇文章的其他人分享解决方案。

除了已有的功能之外,您还可以使用 Azure CLI DevContainer 功能

© www.soinside.com 2019 - 2024. All rights reserved.