Cannot connect to rabbitmq


#1

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: https://circleci.com/gh/BrandEmbassy/webhook-dispatcher/34

Here is a config:

version: 2
jobs:
  build:
    docker:
      - image: brandembassy/php:7.2-fpm-noxdebug
      - image: brandembassy/rabbitmq:latest
        environment:
          RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
          RABBITMQ_DEFAULT_USER: "rabbitmq"
          RABBITMQ_DEFAULT_PASS: "rabbitmq"
          RABBITMQ_DEFAULT_VHOST: "/"
        ports:
          - "15672:15672"
          - "5672:5672"

    working_directory: ~/repo

    steps:
      - checkout

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

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

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

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

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

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


#2

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 127.0.0.1 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.


#3

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

Thanks :slight_smile:


#4

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.


#5

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