dockerdocker-composerabbitmq

How to check rabbitMQ connection(health check) up or not?


I'm running 4 microservice using Docker. Here one service depends on other services. That is why I need to check before using any service other services up or not?

To up all services I'm writing a bash script. For my working purpose, I am using sleep until up properly RabbitMQ.

What is the better solution to check RabbitMQ up or not? While RabbitMQ is not up I have to wait. Now for my working purpose I am using like that -

# wait for rabbitmq container be ready 
sleep 14

This is the docker-compose container for rabbitMQ

rabbitmq:
  image: 'rabbitmq:3.8.9'
  container_name: rabbitmq_dev
  restart: always
  ports:
    - 5675:5672
  environment:
    - RABBITMQ_DEFAULT_USER=rabbit
    - RABBITMQ_DEFAULT_PASS=pass
  depends_on:
    - consul
  networks:
    - my_networks

Solution

  • I think HealthCheck can solve your problem.

    Reference links: Docker Compose wait for container X before starting Y