Answers: <p>If <code>rabbitmq-diagnostics -q ping</code> not working for you, check this</p>
  <pre><code>healthcheck:
    test: rabbitmq-diagnostics check_port_connectivity
    interval: 1s
    timeout: 3s
    retries: 30
  </code></pre>
  <p>In my example I also reduced interval.</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-02-07T19:08:56.857Z
Answers: 2022-04-04T22:14:40.827Z
Answers: 2022-04-04T22:14:40.827Z
Answers: shes
Answers: <p>Your solution is good if you do not own / control the RabbitMQ Compose code but still have to check the service presence and your RabbitMQ image contains the management plugin.</p>
  <p>First of all you are using curl which sends an HTTP request which on the other hand rabbitmq is not HTTP.</p>
  <p>To fix this you can modify you command as follows:</p>
  <pre><code># Note the port 15672 is the RabbitMQ Management UI port
  # It responds with 200 OK and the HTML page which is acceptable for a healcheck
  test: [&quot;CMD&quot;, &quot;curl&quot;, &quot;-f&quot;, &quot;http://localhost:15672&quot;]
  </code></pre>
  <p>Note also that <code>localhost</code> may not work. Instead you should most likely use the RabbitMQ service name declared externally as host name (e.g. <code>http://rabbitmq-service:15672</code>) and ensure your service containing health check is on the same external network with the RabbitMQ server.</p>
  <p>As well you have to have <code>curl</code> or <code>netcat</code> package installed on the Docker image your run the container from. This would require to construct a custom dockerfile.</p>
  <p>Other answers show lots of approaches the rabbitmq team suggests in case the RabbitMQ service is defined in your Docker Compose file.</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-03-25T19:27:16.150Z
Answers: 2024-03-25T17:07:21.157Z
Answers: 2024-03-25T17:07:21.157Z
Answers: Amir Hossein Baghernezad
Answers: <p>I just want to add to above answers about <code>rabbitmq-diagnostics</code>, which worked great, however there was one missing part.</p>
  <pre><code>    depends_on:
        rabbitmq:
          condition: service_healthy
  
    rabbitmq:
      image: rabbitmq:3.8.17-management
      healthcheck:
        test: rabbitmq-diagnostics check_port_connectivity
        interval: 30s
        timeout: 30s
        retries: 10
  </code></pre>
  <p>With that my dependent service waits exactly what is needed to.</p>
  
Answers: CC BY-SA 4.0
Answers: 2024-08-22T19:25:53.403Z
Answers: JFI: [`rabbitmq-diagnostics check_port_connectivity`](https://www.rabbitmq.com/docs/man/rabbitmq-diagnostics.8#check_port_connectivity) is a command that works out of the box and checks whether it can create a new TCP connection to the rabbitmq.
Answers: Mohammad Jawad Barati
Answers: CC BY-SA 4.0
Answers: 2022-08-16T22:28:02.597Z
Answers: 2022-08-16T22:28:02.597Z
Answers: coffekid
Answers: <p>I will go with this, I want to raise issues like <em>&quot;Publishers will be blocked until this alarm clears&quot;</em>:</p>
  <pre><code>    healthcheck:
          test: rabbitmq-diagnostics -q status &amp;&amp; rabbitmq-diagnostics -q check_local_alarms
          interval: 60s
          timeout: 30s
          retries: 3
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2022-07-20T10:16:11.067Z
Answers: As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer).
Answers: Community
Answers: CC BY-SA 4.0
Answers: 2022-07-20T07:58:21.050Z
Answers: 2022-07-20T07:58:21.050Z
Answers: José Ibañez
Answers: <p>You could use the command <code>rabbitmq-diagnostics -q ping</code> in case you just need a basic check.</p>
  <pre><code>healthcheck:
    test: rabbitmq-diagnostics -q ping
    interval: 30s
    timeout: 30s
    retries: 3
  </code></pre>
  <p>More information on how to run more advanced health checks could be found <a href="https://www.rabbitmq.com/monitoring.html#health-checks" rel="noreferrer">here</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-08-13T11:20:53.507Z
Answers: Thanks a million, that's exactly what I needed!  
  
  The docs mention each stage builds on the previous. 
  >"This includes the stage 1 check plus ..."
  
  Do you know if you have to chain the commands? or does each command implicitly cover the previous one?  
  e.g. which do I need for stage 2?
  1. `rabbitmq-diagnostics -q ping && rabbitmq-diagnostics -q status` 
  2. `rabbitmq-diagnostics -q status`
Answers: ConorSheehan1
Answers: CC BY-SA 4.0
Answers: 2020-08-18T14:56:47.453Z
Answers: Option 2 should be enough. Every time the status command returns OK, the ping command would have been successful too. But, the status makes some additional checks.
Answers: pmodernell
Answers: CC BY-SA 4.0
Answers: 2022-07-20T07:22:14.767Z
Answers: Memory alarms are not detected here, ex: "memory resource limit alarm set on ... Publishers will be blocked until this alarm clears"
Answers: José Ibañez
Answers: CC BY-SA 4.0
Answers: 2023-06-22T10:44:58.030Z
Answers: If you have a cluster, then you need to check the node is booting otherwise it blocks the boot. You can use jq and test if the node is not booting for example (Swarm)  : `rabbitmq-diagnostics --formatter=json is_booting | jq --exit-status -n '.result' || rabbitmq-diagnostics -q check_running`
Answers: Ser
Answers: CC BY-SA 4.0
Answers: 2020-08-12T18:13:15.080Z
Answers: 2020-08-12T18:13:15.080Z
Answers: pmodernell
Body: <p>I'm trying to run <code>rabbitMQ</code> using <code>docker-compose</code>, but the service is always starting or unhealthy.<br />
  rabbit is running fine, so I suspect there is something wrong with my health check.</p>
  <p>Running the healthcheck command locally does return a value.</p>
  <pre><code>&gt; curl -f http://localhost:5672
  AMQP    %
  </code></pre>
  <p>But <code>docker-compose ps</code> always says the service is unhealthy (or starting, before it runs out of time).</p>
  <pre><code>&gt; docker-compose ps
  docker-entrypoint.sh rabbi ...   Up (unhealthy)   15671/tcp
  </code></pre>
  <p>Here is what my docker-compose.yml file looks like.</p>
  <pre class="lang-yaml prettyprint-override"><code># docker-compose.yml
  version: '2.3' # note: I can't change this version, must be 2.3
  
  volumes:
    rabbit-data:
  
  services:
    rabbit:
      hostname: 'rabbit'
      image: rabbitmq:3.8.5-management
      healthcheck:
        test: [&quot;CMD&quot;, &quot;curl&quot;, &quot;-f&quot;, &quot;http://localhost:5672&quot;]
        interval: 30s
        timeout: 30s
        retries: 3
      ports:
        - '5672:5672'
        - '15672:15672'
      volumes:
        - 'rabbit-data:/var/lib/rabbitmq/mnesia/'
      networks:
        - rabbitmq
  
  networks:
    rabbitmq:
      driver: bridge
  </code></pre>
  <p>I have also tried using <code>nc</code> instead of <code>curl</code> in the healthcheck, but got the same result.</p>
  <pre class="lang-yaml prettyprint-override"><code>healthcheck:
    test: [ &quot;CMD&quot;, &quot;nc&quot;, &quot;-z&quot;, &quot;localhost&quot;, &quot;5672&quot; ]
  </code></pre>
  <p>From <a href="https://github.com/docker-library/rabbitmq/issues/326" rel="noreferrer">https://github.com/docker-library/rabbitmq/issues/326</a></p>
  
Tags: <docker><docker-compose><rabbitmq>
Title: docker-compose healthcheck for rabbitMQ
UserDisplayName: ConorSheehan1
ThreadText: # docker-compose healthcheck for rabbitMQ
  
  (Asked by: username_0 on 2020-07-29)
  
  I'm trying to run `rabbitMQ` using `docker-compose`, but the service is always starting or unhealthy.  
  rabbit is running fine, so I suspect there is something wrong with my health check.
  
  Running the healthcheck command locally does return a value.
  
  ```
  > curl -f http://localhost:5672
  AMQP    %
  
  ```
  
  But `docker-compose ps` always says the service is unhealthy (or starting, before it runs out of time).
  
  ```
  > docker-compose ps
  docker-entrypoint.sh rabbi ...   Up (unhealthy)   15671/tcp
  
  ```
  
  Here is what my docker-compose.yml file looks like.
  
  ```yaml
  # docker-compose.yml
  version: '2.3' # note: I can't change this version, must be 2.3
  
  volumes:
    rabbit-data:
  
  services:
    rabbit:
      hostname: 'rabbit'
      image: rabbitmq:3.8.5-management
      healthcheck:
        test: ["CMD", "curl", "-f", "http://localhost:5672"]
        interval: 30s
        timeout: 30s
        retries: 3
      ports:
        - '5672:5672'
        - '15672:15672'
      volumes:
        - 'rabbit-data:/var/lib/rabbitmq/mnesia/'
      networks:
        - rabbitmq
  
  networks:
    rabbitmq:
      driver: bridge
  
  ```
  
  I have also tried using `nc` instead of `curl` in the healthcheck, but got the same result.
  
  ```yaml
  healthcheck:
    test: [ "CMD", "nc", "-z", "localhost", "5672" ]
  
  ```
  
  From <https://github.com/docker-library/rabbitmq/issues/326>
  
  **Tags:** docker, docker-compose, rabbitmq
  
  
  ---
  
  ## 5 answers
  
  ### Answer by username_7 on 2020-08-12. Score: 49 | Accepted answer
  
  You could use the command `rabbitmq-diagnostics -q ping` in case you just need a basic check.
  
  ```
  healthcheck:
    test: rabbitmq-diagnostics -q ping
    interval: 30s
    timeout: 30s
    retries: 3
  
  ```
  
  More information on how to run more advanced health checks could be found [here](https://www.rabbitmq.com/monitoring.html#health-checks)
  
  > **Comments:**
  > **username_0**: Thanks a million, that's exactly what I needed!    The docs mention each stage builds on the previous.  >"This includes the stage 1 check plus ..."  Do you know if you have to chain the commands? or does each command implicitly cover the previous one?   e.g. which do I need for stage 2? 1. `rabbitmq-diagnostics -q ping && rabbitmq-diagnostics -q status`  2. `rabbitmq-diagnostics -q status`  
  > **username_7**: Option 2 should be enough. Every time the status command returns OK, the ping command would have been successful too. But, the status makes some additional checks.  
  > **username_5**: Memory alarms are not detected here, ex: "memory resource limit alarm set on ... Publishers will be blocked until this alarm clears"  
  > **username_8**: If you have a cluster, then you need to check the node is booting otherwise it blocks the boot. You can use jq and test if the node is not booting for example (Swarm)  : `rabbitmq-diagnostics --formatter=json is_booting | jq --exit-status -n '.result' || rabbitmq-diagnostics -q check_running`  
  
  ---
  
  ### Answer by username_3 on 2022-08-16. Score: 9
  
  I just want to add to above answers about `rabbitmq-diagnostics`, which worked great, however there was one missing part.
  
  ```
      depends_on:
        rabbitmq:
          condition: service_healthy
  
    rabbitmq:
      image: rabbitmq:3.8.17-management
      healthcheck:
        test: rabbitmq-diagnostics check_port_connectivity
        interval: 30s
        timeout: 30s
        retries: 10
  
  ```
  
  With that my dependent service waits exactly what is needed to.
  
  > **Comments:**
  > **username_4**: JFI: [`rabbitmq-diagnostics check_port_connectivity`](https://www.rabbitmq.com/docs/man/rabbitmq-diagnostics.8#check_port_connectivity) is a command that works out of the box and checks whether it can create a new TCP connection to the rabbitmq.  
  
  ---
  
  ### Answer by username_1 on 2022-02-07. Score: 8
  
  If `rabbitmq-diagnostics -q ping` not working for you, check this
  
  ```
  healthcheck:
    test: rabbitmq-diagnostics check_port_connectivity
    interval: 1s
    timeout: 3s
    retries: 30
  
  ```
  
  In my example I also reduced interval.
  
  
  ---
  
  ### Answer by username_2 on 2023-03-25. Score: 2
  
  Your solution is good if you do not own / control the RabbitMQ Compose code but still have to check the service presence and your RabbitMQ image contains the management plugin.
  
  First of all you are using curl which sends an HTTP request which on the other hand rabbitmq is not HTTP.
  
  To fix this you can modify you command as follows:
  
  ```
  # Note the port 15672 is the RabbitMQ Management UI port
  # It responds with 200 OK and the HTML page which is acceptable for a healcheck
  test: ["CMD", "curl", "-f", "http://localhost:15672"]
  
  ```
  
  Note also that `localhost` may not work. Instead you should most likely use the RabbitMQ service name declared externally as host name (e.g. `http://rabbitmq-service:15672`) and ensure your service containing health check is on the same external network with the RabbitMQ server.
  
  As well you have to have `curl` or `netcat` package installed on the Docker image your run the container from. This would require to construct a custom dockerfile.
  
  Other answers show lots of approaches the rabbitmq team suggests in case the RabbitMQ service is defined in your Docker Compose file.
  
  
  ---
  
  ### Answer by username_5 on 2022-07-20. Score: 1
  
  I will go with this, I want to raise issues like *"Publishers will be blocked until this alarm clears"*:
  
  ```
      healthcheck:
          test: rabbitmq-diagnostics -q status && rabbitmq-diagnostics -q check_local_alarms
          interval: 60s
          timeout: 30s
          retries: 3
  
  ```
  
  > **Comments:**
  > **username_6**: As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer).  
  
  ---
  
  