MM Manuel
MM Manuel

Reputation: 385

econnrefused 127.0.0.1:5672 Rabbit-mq with docker compose

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

Upvotes: 9

Views: 16552

Answers (3)

sandesh ghoti
sandesh ghoti

Reputation: 1

Rabbitmq-service takes time to start, so it better to restart those container who are depend on rabbitmq-service or setTimeout in our service to start connection

if you define depends-on in docker-compose then it does't mean our service will start after rabbitmq-service

please suggest, if you have better solution

Upvotes: 0

Sankha Rathnayake
Sankha Rathnayake

Reputation: 843

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

Upvotes: 0

vivekyad4v
vivekyad4v

Reputation: 14843

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

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

Upvotes: 15

Related Questions