C
C
Crash2021-02-05 11:12:49
RabbitMQ
Crash, 2021-02-05 11:12:49

I can't establish an AMQP connection between two containers, what could be wrong?

My docker-compose.yml config:

version: "3"

networks:
  mydockernet:
    driver: bridge
    name: mydockernet

services:
  # nginx
  nginx-service:
    image: nginx:stable-alpine
    container_name: nginx-container
    ports:
      - "8080:80"
    volumes:
      - ./app:/var/www/project
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php74-service
      - mysql8-service
    networks:
      - mydockernet

  # php
  php74-service:
    build:
      context: .
      dockerfile: ./php/Dockerfile
    container_name: php74-container
    restart: always
    ports:
      - "9000:9000"
    volumes:
      - ./app:/var/www/project
    networks:
      - mydockernet

  # mysql
  mysql8-service:
    image: mysql:8
    container_name: mysql8-container
    ports:
      - "4306:3306"
    volumes:
      - ./mysql:/var/lib/mysql
    command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    restart: always # always restart unless stopped manually
    environment:
        MYSQL_USER: root
        MYSQL_ROOT_PASSWORD: secret
        MYSQL_PASSWORD: secret
    networks:
      - mydockernet

  rabbitmq-service:
    image: 'bitnami/rabbitmq:latest'
    container_name: rabbitmq-container
    ports:
      - "5671:5672"
      - "15671:15672"
    volumes:
      - 'rabbitmq_data:/data'
    networks:
      - mydockernet

  worker-service:
    build:
      context: .
      dockerfile: ./worker/Dockerfile
    container_name: worker-container
    restart: unless-stopped
    depends_on:
      - rabbitmq-service
    ports:
      - "5000:5000"
    volumes:
      - ./app:/var/www/project
    networks:
      - mydockernet

volumes:
  rabbitmq_data:


Dockerfile for the worker:
FROM php:7.4-fpm

RUN apt-get update && apt-get install -y zlib1g-dev g++ git libicu-dev zip libzip-dev zip \
    && docker-php-ext-install intl opcache pdo pdo_mysql \
    && pecl install apcu \
    && docker-php-ext-enable apcu \
    && docker-php-ext-configure zip \
    && docker-php-ext-install zip

RUN docker-php-ext-install sockets
RUN apt-get install -y librabbitmq-dev \
    && pecl install amqp \
    && docker-php-ext-enable amqp

RUN apt-get install -y inetutils-ping

WORKDIR /var/www/project

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN curl -sS https://get.symfony.com/cli/installer | bash

RUN mv /root/.symfony/bin/symfony /usr/local/bin/symfony


Current state:
601cfcc43c39c798450230.png

All containers are connected to the same network:
601cfd047cf9a704147876.png

Pings pass:
601cfd56049cf514689775.png

But still can't connect:
601cfe4abd2b5279280792.png

Log continues:
601d0058ae1f3064359128.png

With this config:
###> symfony/messenger ###
# Choose one of the transports below
# MESSENGER_TRANSPORT_DSN=doctrine://default
MESSENGER_TRANSPORT_DSN=amqp://user:[email protected]:5671/%2f/messages
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
###< symfony/messenger ###


Despite the fact that I went through the browser without problems:
601cfdeac957c767515442.png

Please tell me why I can’t connect through the worker?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Crash, 2021-02-05
@Bandicoot

My mistake was as follows:
In the rabbitmq connection config, it was necessary to specify the internal port 5672, and not the port for the host machine 5671. After I fixed it, I managed to connect using the service name without any problems.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question