title: RabbitMq - Docker-compose - How to fix 'Connection refused 127.0.0.1:5672' exception
body: <p>I have tried several possible solutions on Stack Overflow but nothing seems to work for me.</p>
  
  <p>I am developing microservices using RabbitMQ. The solution contains multiple projects and runs without any problem, but as soon as I use <code>docker-compose</code> option to build the project, Visual Studio throws the following exception:</p>
  
  <blockquote>
    <p>RabbitMQ.Client.Exceptions.BrokerUnreachableException ExtendedSocketException: Connection refused 127.0.0.1:5672 </p>
  </blockquote>
  
  <p>In my solution, I have three projects communicating with each other via RabbitMQ. </p>
  
  <p>Below is the code for my YAML file.</p>
  
  <p><strong>My docker-compose.yaml:</strong></p>
  
  <pre><code>version: '3.4'
  
  services:    
    rabbitmq:
      hostname: webnet
      image: rabbitmq:3.7.2-management
      ports:
        - "15672:15672"
        - "5672:5672"    
      networks:
        - webnet
  
    sql-server-db:
      container_name: sql-server-db
      image: microsoft/mssql-server-linux:2017-latest
      ports:
        - "1433:1433"
      environment:
        SA_PASSWORD: "customerdbalten@123"
        ACCEPT_EULA: "Y"
      networks:
        - webnet
  
    myproject.simulation.api:
      image: ${DOCKER_REGISTRY-}myprojectsimulationapi
      build:
        context: .
        dockerfile: myproject.Simulation.Api/Dockerfile
      links:
        - rabbitmq
      ports:
        - '5000'
      networks:
        - webnet
  
    myproject.updateservice.api:
      image: ${DOCKER_REGISTRY-}myprojectupdateserviceapi
      build:
        context: .
        dockerfile: myproject.updateservice.Api/Dockerfile
      links:
        - rabbitmq
        - sql-server-db
      ports:
        - '5050'
      networks:
        - webnet
  
    myproject.web:
      image: ${DOCKER_REGISTRY-}myprojectweb
      build:
        context: .
        dockerfile: MyProject.Web/Dockerfile
      links:
        - rabbitmq
      ports:
        - '5001'
      networks:
        - webnet
  
  networks:
    webnet:
      driver: bridge
  </code></pre>
  
  <p><strong>My Docker file:</strong></p>
  
  <p>My Dockerfile looks like the following:</p>
  
  <pre><code>FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
  WORKDIR /app
  EXPOSE 80
  EXPOSE 443
  
  FROM microsoft/dotnet:2.2-sdk AS build
  WORKDIR /src
  COPY 
  MyProject.UpdateService.Api/MyProject.UpdateService.Api.csproj MyProject.UpdateService.Api/
  COPY MyProject.Common/MyProject.Common.csproj MyProject.Common/
  RUN dotnet restore MyProject.UpdateService.Api/MyProject.UpdateService.Api.csproj
  COPY . .
  WORKDIR /src/MyProject.UpdateService.Api
  RUN dotnet build MyProject.UpdateService.Api.csproj -c Release -o /app
  
  FROM build AS publish
  RUN dotnet publish MyProject.UpdateService.Api.csproj -c Release -o /app
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app .
  ENTRYPOINT ["dotnet", "MyProject.UpdateService.Api.dll"]
  
  </code></pre>
  
  <p>I've also created another simple solution with nothing but two projects - a sender and receiver - that uses RabbitMQ. This solution throws the same exception while <code>docker-compose</code>ing, otherwise, it just runs. The YAML file has nothing but auto-generated code.</p>