title: Rabbitmq - Docker connection refused on port 5672
body: <p>I have a web server written in Go that interacts with Rabbitmq and Mongodb. When I run all these servers on my machine without containers (rabbitmq url: <code>amqp://guest:guest@localhost:5672</code>) it works fine.</p>
  <p>Now I am trying to run all these services in a separate container. Here is my compose file</p>
  <pre class="lang-yaml prettyprint-override"><code>version: '3'
  services:
    rabbitmq:
      image: rabbitmq
      container_name: rabbitmq
      ports:
        - 5672:5672
    mongodb:
      image: mongo
      container_name: mongodb
      ports:
        - 27017:27017
    web:
      build: .
      image: palash2504/collect
      container_name: collect-server
      restart: on-failure
      ports:
        - 3000:3000
      depends_on:
        - rabbitmq
        - mongodb
      links: [&quot;rabbitmq&quot;, &quot;mongodb&quot;]
  
  networks:
    default:
      external:
        name: collect-net
  </code></pre>
  <p>This is my servers dockerfile</p>
  <pre><code>FROM golang
  
  ENV GO111MODULE=on
  
  
  WORKDIR /app
  
  COPY go.mod .
  COPY go.sum .
  
  RUN go mod download
  
  COPY . .
  
  RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
  
  EXPOSE 3000
  
  
  ENTRYPOINT [&quot;/app/social-cops-assignment&quot;]
  </code></pre>
  <p>My server can't seem to connect to rabbitmq. This is the log message I get when running <code>docker compose up</code> and the rabbitmq url in my config being <code>amqp://guest:guest@rabbitmq:5672</code> (since the container name is rabbitmq I replace localhost with rabbitmq so that my server is able to find the rabbitmq container)</p>
  <pre><code>collect-server | 2019/03/10 08:50:51 Failed to connect to AMQP compatible broker at: amqp://guest:guest@rabbitmq:5672/, with errror: dial tcp 172.24.0.3:5672: connect: connection refused
  </code></pre>
  <p>But rabbitmq seems to be ready to accept connections. These are the last two lines of the rabbitmq logs from <code>docker-compose up</code></p>
  <pre><code>rabbitmq    | 2019-03-10 08:50:55.164 [info] &lt;0.489.0&gt; accepting AMQP connection &lt;0.489.0&gt; (172.24.0.4:49784 -&gt; 172.24.0.3:5672)
  rabbitmq    | 2019-03-10 08:50:55.205 [info] &lt;0.489.0&gt; connection &lt;0.489.0&gt; (172.24.0.4:49784 -&gt; 172.24.0.3:5672): user 'guest' authenticated and granted access to vhost '/'
  </code></pre>
  <p>I am new to docker-networking and I don't know what am I doing wrong? Is it the rabbitmq address that I am using or I need some additional configuration with respect to rabbitmq or expose some ports?</p>