简体   繁体   English

docker-compose 在本地运行 Azure 功能

[英]docker-compose to run Azure Functions locally

We are building a system that some customers will run in Azure and some will run in Docker on their own hardware via docker-compose.我们正在构建一个系统,一些客户将在 Azure 中运行,一些客户将通过 docker-compose 在他们自己的硬件上运行在 Docker 中。 We are basing our Microservices on Azure Functions.我们的微服务基于 Azure 函数。

I have written a docker-compose file to setup the various images (web site, Azure Functions and RabbitMQ)我编写了一个 docker-compose 文件来设置各种图像(网站,Azure 函数和 RabbitMQ)

The docker-compose looks like this (Simplified): docker-compose 看起来像这样(简化):

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

When the docker-compose starts up, I get this error when the Azure Function project is started:当 docker-compose 启动时,当 Azure Function 项目启动时出现此错误:

abmicroservice_1 | abmicroservice_1 | No job functions found.未找到工作职能。 Try making your job classes and methods public.尝试公开您的工作类别和方法。 If you're using binding extensions (eg Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (eg builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).如果您使用绑定扩展(例如 Azure 存储、ServiceBus、计时器等),请确保您已在启动代码中调用了扩展的注册方法(例如 builder.AddAzureStorage()、builder.AddServiceBus( )、builder.AddTimers() 等)。

But when I run the same Azure Function using the func.exe tool or Visual Studio Debug, it runs fine.但是当我使用 func.exe 工具或 Visual Studio Debug 运行相同的 Azure Function 时,它运行良好。

I am guessing that the issue is my various host.json and the like and settings in docker-compose.yml .我猜这个问题是我的各种 host.json 等和 docker-compose.yml 中的设置

My Function is just a hello-world test that runs great when Visual Studio 2019 runs it:我的 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}");
    }
}

Few thing that could could solve it:很少有东西可以解决它:

  • Check the connection strings检查连接字符串

  • Make sure the connection strings are given as env variables to your docker (look into function.json and the value of "connection" should be the name of env variable with connection string)确保将连接字符串作为环境变量提供给 docker(查看 function.json 并且“连接字符串”的值应该是连接字符串的名称)

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

This means your docker should have a env variable "connectionVariable" with the connection string (to service bus in this example)这意味着您的 docker 应该有一个带有连接字符串的环境变量“connectionVariable”(在本例中为服务总线)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM