【问题标题】:docker-compose to run Azure Functions locallydocker-compose 在本地运行 Azure Functions
【发布时间】:2020-09-14 21:01:16
【问题描述】:

我们正在构建一个系统,一些客户将在 Azure 中运行,而一些客户将通过 docker-compose 在他们自己的硬件上的 Docker 中运行。我们的微服务基于 Azure Functions。

我已经编写了一个 docker-compose 文件来设置各种图像(网站、Azure Functions 和 RabbitMQ)

docker-compose 看起来像这样(简化):

version: "3"
services:
  abmicroservice:
    build:
       context: ./AbMicroservice
  depends_on:
    - rabbitmq

docker-compose 启动时,Azure Function 项目启动时出现此错误:

abmicroservice_1 |未找到工作职能。尝试制作你的 工作类和方法公开。如果您使用绑定扩展 (例如 Azure Storage、ServiceBus、Timers 等)确保您已调用 启动代码中扩展的注册方法 (例如 builder.AddAzureStorage()、builder.AddServiceBus()、 builder.AddTimers() 等)。

但是当我使用 func.exe 工具或 Visual Studio Debug 运行相同的 Azure Function 时,它运行良好。

我猜问题出在我的各种 host.json 之类以及 docker-compose.yml 中的设置

My Function 只是一个 hello-world 测试,在 Visual Studio 2019 运行时运行良好:

public static class TriggerFunction
{
    [FunctionName("TriggerFunction")]
    public static void Run(
        [RabbitMQTrigger("hello")] string message,
        ILogger log)
    {
        log.LogInformation($"************* Message received from RabbitMQ trigger: {message}");
    }
}

【问题讨论】:

  • 您将哪个 Docker 映像用作 Azure Function 应用程序的运行时?作为一种选择,尝试使用“自包含”发布您的函数应用,这可能有助于在容器中运行它

标签: azure docker docker-compose azure-functions azure-functions-runtime


【解决方案1】:

几乎没有什么可以解决的:

  • 检查连接字符串

  • 确保将连接字符串作为环境变量提供给您的 docker(查看 function.json 并且“connection”的值应该是带有连接字符串的环境变量的名称)

     {
    "scriptFile": "__init__.py",
    "bindings": [
     {
       "name": "msg",
       "type": "serviceBusTrigger",
       "direction": "in",
       "queueName": "nameOfTheQue",
       "connection": "connectionVariable"
     }
    ]
    }
    

这意味着你的 docker 应该有一个带有连接字符串的环境变量“connectionVariable”(在本例中为服务总线)

【讨论】:

    猜你喜欢
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    相关资源
    最近更新 更多