title: RabbitMq refuses connection when run in docker
body: <p>My docker-compose file looks like this:</p>
  
  <pre><code>version: '2'
  
  services:
    explore:
      image: explore
      build:
        context: ./Explore
        dockerfile: VsDockerfile
      environment:
        - "ElasticUrl=http://localhost:9200"
        - "RabbitMq/Host=localhost"
        - "RabbitMq/Username=guest"
        - "RabbitMq/Password=guest"
      networks:
        - localnet
  
    elasticsearch:
      image: docker.elastic.co/elasticsearch/elasticsearch:5.4.3
      container_name: elasticsearch
      environment:
        - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      ports:
        - 9200:9200
      volumes:
        - ./esdata:/usr/share/elasticsearch/data
      networks:
        - localnet
  
    rabbit:
      image: rabbitmq:3.6.7-management
      hostname: rabbit
      ports:
        - 15672:15672
        - 5672:5672
      networks:
        - localnet
  
  networks:
    localnet:
      external:
        name: localnet
  </code></pre>
  
  <p>If I type <a href="http://localhost:15672" rel="noreferrer">http://localhost:15672</a> in the browser, I get the rabbitmq interface, but if I tries to connect from my Explore project like this: </p>
  
  <pre><code>public SqlToRabbitProcessor(SqlToRabbitRepository sqlToRabbitRepository)
  {
      _sqlToRabbitRepository = sqlToRabbitRepository;
  
      var factory = new ConnectionFactory
      {
          HostName = Environment.GetEnvironmentVariable("RabbitMq/Host"),
          UserName = Environment.GetEnvironmentVariable("RabbitMq/Username"),
          Password = Environment.GetEnvironmentVariable("RabbitMq/Password")
      };
  
      var rabbit = factory.CreateConnection();
      channel = rabbit.CreateModel();
  }
  </code></pre>
  
  <p>Then it breaks in the line</p>
  
  <pre><code>var rabbit = factory.CreateConnection();
  </code></pre>
  
  <p>with the error saying</p>
  
  <p>ExtendedSocketException: Connection refused 127.0.0.1:5672
  System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)</p>
  
  <p>ConnectFailureException: Connection failed
  RabbitMQ.Client.EndpointResolverExtensions.SelectOne(IEndpointResolver resolver, Func selector)</p>
  
  <p>BrokerUnreachableException: None of the specified endpoints were reachable
  RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, string clientProvidedName)</p>