【问题标题】:Usage of Command Override in Azure Container Instances within Azure Portal在 Azure 门户中的 Azure 容器实例中使用命令覆盖
【发布时间】:2021-05-06 02:30:28
【问题描述】:

我正在尝试使用 Azure 门户从 Azure 容器实例中的私有存储库部署基于 Windows 的容器,但我不确定我是否在“高级”部分正确(可能我没有)。问题是我必须在运行时传递一个参数,该参数设置许可证服务器的值,以便需要与许可证服务器建立连接的特定应用程序可以启动。 通常,容器的运行命令如下所示:

docker run IMAGE:TAG -LicenseServer Port@Host

我在 Dockerfile 中的入口点是一个 Powershell 脚本“Start.ps1”,它请求所提到的许可证服务器的相应值。

我已经阅读了manual,因此我插入了以下字符串来覆盖并传递参数:

[ "cmd", "Start.ps1", "-LicenseServer", "<Port>@<Hostname>"]

部署 ACI 后,Container 会进入“运行”状态几秒钟,然后再次终止。根据日志,它无论如何都没有工作。

所以我想知道,部署容器以使其运行的正确方法是什么?

非常感谢您!

除了我的问题,要获得更多上下文: ACI 是在 Azure 门户中创建的:

我使用了以下设置,请参阅 JSON 视图:

{
"properties": {
    "sku": "Standard",
    "provisioningState": "Succeeded",
    "containers": [
        {
            "name": "<name>",
            "properties": {
                "image": "<image name>",
                "command": [
                    "powershell",
                    "Start.ps1",
                    "-LicenseServer",
                    "<port>@<host>"
                ],
                "ports": [
                    {
                        "protocol": "TCP",
                        "port": 80
                    }
                ],
                "environmentVariables": [],
                "instanceView": {
                    "restartCount": 1,
                    "currentState": {
                        "state": "Terminated",
                        "finishTime": "2021-04-28T06:06:22.2263538Z",
                        "detailStatus": "Container stopped per client request"
                    },
                    "previousState": {
                        "state": "Waiting",
                        "detailStatus": "CrashLoopBackOff: Back-off restarting failed"
                    }
                },
                "resources": {
                    "requests": {
                        "memoryInGB": 8,
                        "cpu": 1
                    }
                }
            }
        }
    ],
    "initContainers": [],
    "imageRegistryCredentials": [
        {
            "server": "<login server>",
            "username": "<user>"
        }
    ],
    "restartPolicy": "OnFailure",
    "ipAddress": {
        "ports": [
            {
                "protocol": "TCP",
                "port": 80
            }
        ],
        "type": "Public",
        "dnsNameLabel": "mycontainerdns",
        "fqdn": "mycontainerdns.westeurope.azurecontainer.io"
    },
    "osType": "Windows",
    "instanceView": {
        "events": [],
        "state": "Stopped"
    }
},
"id": "/subscriptions/<subscription id>",
"name": "<aci name>",
"type": "Microsoft.ContainerInstance/containerGroups",
"location": "westeurope",
"tags": {}

}

【问题讨论】:

    标签: azure docker docker-for-windows azureportal azure-container-instances


    【解决方案1】:

    其实cmd只是告​​诉你什么时候需要连接windows容器实例,需要使用命令:

    az container exec -g resource_group_name -n container_group_name --container-name container_name --exec-command "cmd"
    

    但是当你想覆盖 CMD 命令时,你需要像这样传递参数:

    ["powershell", "Start.ps1", "-LicenseServer", "<Port>@<Hostname>"]
    

    表示需要在cmd终端执行Powershell脚本。

    【讨论】:

    • 嗨,谢谢你的答案,但不幸的是它也没有工作......在json视图的sn-p下面:......“provisioningState”:“Succeeded”,“containers” : [ { "name": "containertest", "properties": { "image": ":", "command": [ "powershell", "Start.ps1", "-LicenseServer ", "@" ], ...
    • @bianconero 好吧,你可以试试命令-LicenseServer Port@Host。请记住,在使用参数--command-line 创建 ACI 时添加命令。
    • 不幸的是,与 Azure 门户的设置相关的上述方法均无效。甚至没有得到任何日志。根据 Azure CLI 方法:到目前为止我还没有这方面的经验。
    • @bianconero 您的意思是您在 Azure 门户中工作吗?你能分享一下你用你的图像创建 ACI 的方法吗?
    • @bianconero 这个问题有什么更新吗?它解决了你的问题吗?
    【解决方案2】:

    我终于找到了解决办法。 “命令覆盖”中提供的命令字符串是错误的。 我尝试了几个版本,但现在可以使用以下版本:

    [ "powershell", "C:/Windows/Scripts/Start.ps1", "-LicenseServer", "<port>@<host>" ]
    

    现在我在 ACI 部署中获取日志和容器的运行状态。

    之前,我已经按照第一个答案中的建议进行了尝试:(以及其他)

    ["powershell", "Start.ps1", "-LicenseServer", "<Port>@<Hostname>"]
    

    但这似乎在 ACI 中不起作用,因为找不到“Start.ps1”脚本尽管我已经在 Dockerfile 中设置了工作目录,当然它在我的 Rancher 部署中也可以使用(只需提供“- LicenseServer PortatHost")。

    因此,作为结论,当文件作为容器内的入口点时,您必须提供文件的完整路径。

    非常感谢您的帮助!

    【讨论】:

      猜你喜欢
      • 2015-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多