Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I connect Flower to the broker RabbitMQ in docker-compose

How I can connect Flower to RabbitMQ. My celery running tasks do not appear on Flower. Although they are running fine. On the Flower UI, when I click on "broker", I get this error message on the terminal [E 210326 10:53:07 broker:78] RabbitMQ management API call failed: Timeout while connecting

This is my docker-compose file:

version: "3.8"

services:
    base:
        container_name: base
        image: postgres:13
        ports:
            - "5433:5432"
        environment:
            - POSTGRES_USER=${POSTGRES_USER}
            - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
            - POSTGRES_DB=${POSTGRES_DB}
        volumes:
            - /var/lib/postgresql/data
    api:
        build:
            context: ./api/
            dockerfile: Dockerfile
        volumes:
            - ./api/app:/app/app
        ports:
            - "1000:80"
        depends_on:
            - base
        env_file:
            - .env
        command: ["/start-reload.sh"]

    frontend:
        build:
            context: ./frontend/
            dockerfile: Dockerfile
        ports:
            - "3000:3000"
        volumes:
            - /app/node_modules
            - ./frontend:/app
        environment:
            - NODE_ENV=development
        stdin_open: true
        links:
            - api

    rabbitmq:
        image: "bitnami/rabbitmq:latest"
        ports:
            - "4369:4369"
            - "5672:5672"
            - "25672:25672"
            - "15672:15672"
        volumes:
            # - "rabbitmq_data:/bitnami"
            - /bitnami

    redis:
        image: "bitnami/redis:latest"
        environment:
            - REDIS_PASSWORD=password123
        ports:
            - "6379:6379"
        volumes:
            # - "redis_data:/bitnami/redis/data"
            - /bitnami/redis/data

    flower:
        image: mher/flower
        command: ["flower", "--broker=amqp://user:bitnami@rabbitmq:5672//", "--port=8888"]
        ports:
            - 8888:8888
        depends_on:
            - rabbitmq
            - redis

    worker:
        build:
            context: ./api/
            dockerfile: Dockerfile.celery
        depends_on:
            - rabbitmq
            - redis
        volumes:
            - ./api/app:/app
        command: celery -A app.worker.celery_worker worker --loglevel=INFO --concurrency=4 -Q test-queue
like image 976
Sami Al-Subhi Avatar asked Sep 20 '25 10:09

Sami Al-Subhi


1 Answers

I also suffered from the same problem in my tests of last three days. Flower correctly worked only once during the tests. And I failed to identify why it worked at that time.

For me, the only method to solve this problem was downgrading the docker image from mher/flower:latest or mher/flower:0.9.7 to mher/flower:0.9.5. Changing command line options, environment variables, and docker-compose.yml contents did not help. Everything works fine after the downgrade.


Note. My environment was

  • Machine - Windows 10 with WSL2
  • Main - ubuntu:20.04 with Django 3.1.7, celery[librabbitmq,redis] 5.0.5, django-celery-beat 2.2.0
  • Celery Broker - rabbitmq:management
  • Celery ResultBackend - redis:latest
  • Celery Flower - mher/flower:latest > mher/flower:0.9.5
like image 156
J. Choi Avatar answered Sep 22 '25 09:09

J. Choi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!