Search code examples
dockerdocker-composerabbitmqcontainersazure-web-app-service

RabbitMQ container not reachable in Azure Web App for Containers


I have following docker-compose content:

version: '3.4'

services:
  reporting.service:
    image: xxx.azurecr.io/beta/reporting.service
    environment:
      - ASPNETCORE_ENVIRONMENT=Docker
    ports:
      - "5003:80" 

  messaging.bus:
    image: rabbitmq:3-management
    environment:
      - RABBITMQ_DEFAULT_USER=user
      - RABBITMQ_DEFAULT_PASS=user
      - RABBITMQ_DEFAULT_VHOST=test
    links:
      - reporting.service
    ports:
      - "15672"
      - "5672"

  web.frontend:
    image: xxx.azurecr.io/beta/web.frontend
    ports:
      - "3000:80"

When running above locally on my machine using docker everything works fine and my reporting.service is able to connect to the messaging.bus (RabbitMQ) without any problem.

Connection string looks something like this:

"EventBus": {
    "ConnectionString": "amqp://user:[email protected]:5672/test"
  },

When I push my images to Azure container registry and try to use it in Azure web app for containers then following exception is thrown in reporting.service container:

RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable ---> System.AggregateException: One or more errors occurred. (Connection failed) ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: No such device or address

FYI, I implemented Polly retry policy in the reporting.service when connecting to the RabbitMQ so that code is executed multiple times in case of broker not available. To make sure that RabbitMQ container is up and running (which I confirmed also looking at the logs).

What I'm doing wrong? Why I'm not able to see rabbitMq instance from other containers?

Thanks for the help!


Solution

  • I have had a similar issue on Azure App Services, the way I solved it was using the links keyword. As I see from your docker-compose you are linking it in the wrong way. The reason why it works locally is because the containers are in the same local network.

    Have you tried to link reporting.service to messaging.bus instead?

    Also check this answer here, docker official documentation here and docker compose supported commands on Azure here.

    I have also found an interesting article here that says how to make two containers depending on each-other.

    I hope this helps!