Cannot connect to rabbitmq


Hi, I have an issue that I am not able to connect to RabbitMQ. I start image with rabbit (the same image runs just fine locally - and acording to logs, it’s working also in CircleCI).

This is the build:

Here is a config:

version: 2
      - image: brandembassy/php:7.2-fpm-noxdebug
      - image: brandembassy/rabbitmq:latest
          RABBITMQ_DEFAULT_USER: "rabbitmq"
          RABBITMQ_DEFAULT_PASS: "rabbitmq"
          - "15672:15672"
          - "5672:5672"

    working_directory: ~/repo

      - checkout

      - restore_cache:
            - v1-dependencies-{{ checksum "composer.lock" }}
            - v1-dependencies-

      - run: composer install -n --prefer-dist

      - save_cache:
            - ./vendor
          key: v1-dependencies-{{ checksum "composer.lock" }}

      - run: composer test
      - run: composer test-integration
      - run: composer phpstan

Error: unable to connect to tcp:// (Connection refused)

I have tried a lot of conbinations bu its all the same.


Which step does the error occur in? I would guess that you are reaching your need for Rabbit prior to the service fully starting up. You could try something like this:

- run: sleep 5 && composer test

Also, I only just became aware of the multiple image thing, and I am trying to get my head around it. Is the first one the container in which the run steps happen, and Rabbit a separately launched container? If so, I wonder if is not going to work, because you’re in one of two parallel containers, and you’d need to be on the host for that to work.

I’d guess that Docker Compose would be a good way to go (it’s what I do) though perhaps there is something I am not aware of with using multiple images.


Thanks a lot for tip. I needed to put sleep 10 but it works now! Yay!

Thanks :slight_smile:


Great stuff @Achse. If you want to save some valuable build seconds, then swap that for a script that periodically makes a connection to the queue, with say 0.5 sec between each attempt. It can time out after 10 seconds, but should normally succeed earlier than that.


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.