简体   繁体   中英

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. We are basing our Microservices on Azure Functions.

I have written a docker-compose file to setup the various images (web site, Azure Functions and RabbitMQ)

The docker-compose looks like this (Simplified):

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:

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.).

But when I run the same Azure Function using the func.exe tool or Visual Studio Debug, it runs fine.

I am guessing that the issue is my various host.json and the like and settings in docker-compose.yml .

My Function is just a hello-world test that runs great when Visual Studio 2019 runs it:

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)

     { "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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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