econnrefused 127.0.0.1:5672 Rabbit-mq with docker compose

Viewed 5578

I am not able to connect a node.js app with rabbit-mq server. Postgres is correctly connected. I don't know why I have a connection refused.

version: "3"
networks:
app-tier:
  driver: bridge

services:
db:
  image: postgres
  environment:
    - POSTGRES_USER=dockerDBuser
    - POSTGRES_PASSWORD=dockerDBpass
    - POSTGRES_DB=performance
  ports:
    - "5433:5432"
  volumes:
    - ./pgdata:/var/lib/postgresql/data
  networks:
    - app-tier

rabbitmq:
  image: rabbitmq:3.6.14-management
  healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:5672"]
      interval: 30s
      timeout: 10s
      retries: 5
  ports:
    - "0.0.0.0:5672:5672"
    - "0.0.0.0:15672:15672"
  networks:
    - app-tier
app:
  build: .
  depends_on:
    - rabbitmq
    - db
  links:
    - rabbitmq
    - db
  command: npm run startOrc
  environment:
    DATABASE_URL: postgres://dockerDBuser:dockerDBpass@db:5432/asdf
  restart: on-failure
  networks:
    - app-tier

It seems it's trying to connect to the host rabbitmq instead of the container rabbitmq

2 Answers

Try changing env variable CLOUDAMQP_URL to amqp://rabbitmq:5672

You can call service by it's name i.e rabbitmq.

This error also comes up if you haven't started docker and run rabbitmq server. So if in case if someone who's reading this post gets the same error, please check whether your rabbitmq server is running.

You can use below command to run the rabbitmq server. (5672 is the port of that server)
docker run -p 5672:5672 rabbitmq

Related