docker-composeazure-functionsazure-queuesdocker-networkazurite

Send a azure queue message in a docker container to a queue triggered function in another docker container


It is really difficult to explain. I am not expert in docker. I will try it.

I have 3 components:

  1. 1 container with Azurite
  2. 1 container with a queue function
  3. Microsoft Azure Storage Explorer in the host.

I am using docker-compose.yml to reach my goal.

After two day I could configure correctly the Azurite container to communicate correctly with the Storage Explorer in the host. Here the portion of code in my composer file:

services:
  storage:
    image: mcr.microsoft.com/azure-storage/azurite
    container_name: storage
    restart: always
    ports:
      - 7777:10000
      - 8888:10001
      - 9999:10002   
    environment: 
      - "AZURITE_ACCOUNTS=devnotificationsstorage:Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
    command: "azurite -l /workspace -d /workspace/debug.log --blobPort 10000 --blobHost 0.0.0.0 --queuePort 10001 --queueHost 0.0.0.0 --tablePort 10002 --tableHost 0.0.0.0"
    volumes: 
      - "./datadir/azurite:/workspace"

I mapped the port 7777 in my host with the port 10000 of the container with Azurite. I cannot use the port 10000 in my host because it is already used by Storage Explorer with another local container. However I find strange that everything works setting port 8888 on the host. Here a screen of Sotrage Explorer:

enter image description here

Surely I haven'y understood something.

In any case, now I can correctly insert the message in the containerized queue from the Storage Explorer. But when I insert the message in the queue I expect to receive the message on the queue container. I let you see the whole compose file:

version: '3.4'

services:
  storage:
    image: mcr.microsoft.com/azure-storage/azurite
    container_name: storage
    restart: always
    ports:
      - 7777:10000
      - 8888:10001
      - 9999:10002   
    environment: 
      - "AZURITE_ACCOUNTS=devnotificationsstorage:Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
    command: "azurite -l /workspace -d /workspace/debug.log --blobPort 10000 --blobHost 0.0.0.0 --queuePort 10001 --queueHost 0.0.0.0 --tablePort 10002 --tableHost 0.0.0.0"
    volumes: 
      - "./datadir/azurite:/workspace"
    networks:
      - shared_network

  xxx.notifications.azurefunction.emails:
    image: ${DOCKER_REGISTRY-}xxxgonotificationsazurefunctionemails
    container_name: notifications_email
    build:
      context: .
      dockerfile: XXX.Notifications.AzureFunction.Emails/Dockerfile
    depends_on: 
      - storage  
    networks:
      - shared_network

networks:
  shared_network:

And here the localhost.settings.json file:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
    "StorageConnectionString": "UseDevelopmentStorage=true"
  }
}

Please, note that if I send a message from local queue on port 10000 (the non-dockerized queue), I receive the message on the queue triggered function. But if I send the queue from the dockerized queue nothing happend.

I also thought that perhpas, the connection string is wrong. So I changed the StorageConnectionString with the value I see in the Storage explorer. That is the new localhost.settings.json file:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
    "StorageConnectionString": "AccountName=devnotificationsstorage;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;DefaultEndpointsProtocol=http;BlobEndpoint=http://127.0.0.1:7777/devnotificationsstorage;QueueEndpoint=http://127.0.0.1:8888/devnotificationsstorage;TableEndpoint=http://127.0.0.1:9999/devnotificationsstorage;"
  }
}

In this case, when I write a message on the dockerized queue (and just when I write the message on the queue), I get this error:

Azure.Core: Connection refused (127.0.0.1:8888). System.Net.Http: Connection refused (127.0.0.1:8888). System.Net.Sockets: Connection refused.

How do I have to configure my containers?

Thank you.


Solution

  • This connection string is wrong:

    "StorageConnectionString": "AccountName=devnotificationsstorage;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;DefaultEndpointsProtocol=http;BlobEndpoint=http://127.0.0.1:7777/devnotificationsstorage;QueueEndpoint=http://127.0.0.1:8888/devnotificationsstorage;TableEndpoint=http://127.0.0.1:9999/devnotificationsstorage;"

    I must replace the host 127.0.0.1 and the ports with the ones I defined for my container.

    First of all, the host. We can use the same name we used to define the container in the compose. In my case storage (second line):

    services:
      storage: <-- This is thehost name
        image: mcr.microsoft.com/azure-storage/azurite
        container_name: storage
        restart: always
        ports:
          - 7777:10000
          - 8888:10001
          - 9999:10002   
        environment: 
          - "AZURITE_ACCOUNTS=devnotificationsstorage:Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
        command: "azurite -l /workspace -d /workspace/debug.log --blobPort 10000 --blobHost 0.0.0.0 --queuePort 10001 --queueHost 0.0.0.0 --tablePort 10002 --tableHost 0.0.0.0"
        volumes: 
          - "./datadir/azurite:/workspace"
        networks:
          - shared_network
    

    Second I mapped the ports of my service in this way:

        ports:
          - 7777:10000
          - 8888:10001
          - 9999:10002  
    

    That means host:container. So every Http message sent on port 8888 of the host (in the context of Docker) will be received on port 10001 in my container.

    So if I have to check if there are messages in the queue of my container I must change the connection string in this way:

    "StorageConnectionString": "AccountName=devnotificationsstorage;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;DefaultEndpointsProtocol=http;BlobEndpoint=http://storage:10000/devnotificationsstorage;QueueEndpoint=http://storage:10001/devnotificationsstorage;TableEndpoint=http://storage:10002/devnotificationsstorage;"