title: I am unable to connect to rabbitmq server in docker
body: <p>I am using docker compose to run a sbt process which connect to rabbitmq-server . Following is my docker compose file : -</p>
  
  <pre><code>version: "3"
  services:
    web:
      # replace username/repo:tag with your name and image details
      image: abhishekkumargaya/messanger
      ports:
        - "1883:1883"
      links:
        - rabbit-server
        - redis
        - mysql
      networks:
        - webnet
    rabbit-server:
      image: "rabbitmq:3-management"
      hostname: localhost
      environment:
        #RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
        RABBITMQ_DEFAULT_USER : guest
        RABBITMQ_DEFAULT_PASS : guest
      ports:
        - "5672:5672"
        - "15672:15672"
  
      networks:
        - webnet
  
    redis:
      image: "redis:alpine"
  
    mysql:
      image: mysql
      container_name: database.dev
      command: mysqld --user=root --verbose
  
      ports:
        - "3306:3306"
      environment:
        MYSQL_DATABASE: "user_messages"
        MYSQL_USER: "test"
        MYSQL_PASSWORD: "root"
        MYSQL_ROOT_PASSWORD: "root"
        MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
  
  networks:
    webnet:
  volumes:
    redis-data:
  </code></pre>
  
  <p>I am getting connection refused error. I am using default value to connect to rabbit server in my code . </p>
  
  <pre><code>private lazy val factory = new ConnectionFactory
  val connection = factory.newConnection()
  </code></pre>
  
  <p>My docker file : - </p>
  
  <pre><code>FROM openjdk:8
  ENV SBT_VERSION 0.13.16
  RUN \
    curl -L -o sbt-$SBT_VERSION.deb http://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb &amp;&amp; \
    dpkg -i sbt-$SBT_VERSION.deb &amp;&amp; \
    rm sbt-$SBT_VERSION.deb &amp;&amp; \
    apt-get update &amp;&amp; \
    apt-get install sbt &amp;&amp; \
    sbt sbtVersion
  
  WORKDIR /app
  ADD target/scala-2.11/messanger-assembly-1.0.jar /app
  EXPOSE 1883
  CMD java -jar messanger-assembly-1.0.jar
  </code></pre>
  
  <p>The error which I am getting is as follows :-</p>
  
  <pre><code>Caused by: java.net.ConnectException: Connection refused (Connection refused)
  web_1            |  at java.net.PlainSocketImpl.socketConnect(Native Method)
  web_1            |  at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
  web_1            |  at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
  web_1            |  at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
  web_1            |  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
  web_1            |  at java.net.Socket.connect(Socket.java:589)
  web_1            |  at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60)
  web_1            |  at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:62)
  web_1            |  at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:99)
  web_1            |  at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:948)
  web_1            |  at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:907)
  web_1            |  at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:865)
  web_1            |  at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1018)
  web_1            |  at com.abhishek.rabbitmq.RabbitMqConnectionFactory$.&lt;init&gt;(RabbitMqConnectionFactory.scala:15)
  web_1            |  at com.abhishek.rabbitmq.RabbitMqConnectionFactory$.&lt;clinit&gt;(RabbitMqConnectionFactory.scala)
  </code></pre>
  
  <p>I am not properly understanding how these variable works :-</p>
  
  <pre><code>hostname: localhost
  environment:
    #RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
    - RABBITMQ_DEFAULT_USER = guest
    - RABBITMQ_DEFAULT_PASS = guest
  </code></pre>
  
  <p>I kept this variable like this because by default my client is using host as localhost , user as guest and password as guest to connect to rabbitmq-server
  If I am just running rabbitmq-server image with command - </p>
  
  <pre><code>docker-compose up --build
  </code></pre>
  
  <p>I am able to connect it through my localmachine .</p>