title: How to connect to rabbitmq in one docker container from a service sitting in another
body: <p>I am starting a container for rabbitmq and another with my spring boot service using the following docker-compose.yaml</p>
  
  <pre><code>version: '3'
  services:
    messaging:
      image: "messaging"
      ports: 
       - "7878:9876"
      depends_on:
       - rmq
    rmq:
      image: "rabbitmq:management"
      hostname: "rabbitmqhost"
      container_name: "rabbit-mq"
      ports: 
       - "15672:15672"
       - "5672:5672"
  </code></pre>
  
  <p>Now rabbitmq management is accessible at <code>http://localhost:15672/</code> and the service is accessible at <code>http://localhost:7878</code></p>
  
  <p>The service is supposed to push messages into rabbitmq. When I hit the restAPI <code>http://localhost:7878/sendPersonDetails</code> it is unable to connect to rabbitmq.</p>
  
  <p>Following is the error response I am getting-</p>
  
  <p><code>error occurred in message handler [org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint@3e66d8c7]; nested exception is org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)</code></p>
  
  <p>Following is my <code>application.properties</code> file-</p>
  
  <pre><code>spring.cloud.stream.bindings.output.destination=person
  spring.cloud.stream.bindings.output.content-type=application/json
  
  server.port=9876
  </code></pre>
  
  <p>How do I change my docker-compose configuration or service configuration to make it work? Any help's appreciated.</p>