2

I have a simple FastAPI app. I am using celery for async task processing and flower dashboard for monitoring tasks

My main application is running on port 80

My flower dashboard for task monitoring is running on port 5556

Now I want to map the port to the app endpoint, something like - http://localhost/flower-dashboard

Here is my docker-compose.yml file:

version: '3.8'

services:

  web:
    build: ./project
    ports:
      - 80:80
    command: uvicorn main:app --host 0.0.0.0 --reload
    volumes:
      - ./project:/usr/src/app
    environment:
      - CELERY_BROKER_URL=redis://:password@redis:6379/0
      - CELERY_RESULT_BACKEND=redis://:password@redis:6379/0
    depends_on:
      - redis

  worker:
    build: ./project
    command: celery worker --app=worker.celery --loglevel=info --logfile=logs/celery.log
    volumes:
      - ./project:/usr/src/app
    environment:
      - CELERY_BROKER_URL=redis://:password@redis:6379/0
      - CELERY_RESULT_BACKEND=redis://:password@redis:6379/0
    depends_on:
      - web
      - redis

  redis:
    image: public.ecr.aws/ubuntu/redis:5.0-20.04_edge
    restart: always
    command: /bin/sh -c "redis-server --requirepass $$REDIS_HOST_PASSWORD"
    env_file:
      - redis.env
  dashboard:
    build: ./project
    command:  flower --app=worker.celery --port=5555 --broker=redis://:password@redis:6379/0
    ports:
      - 5556:5555
    environment:
      - CELERY_BROKER_URL=redis://:password@redis:6379/0
      - CELERY_RESULT_BACKEND=redis://:password@redis:6379/0
    depends_on:
      - web
      - redis

Any help would be highly appreciated, thanks!

Ishaan007
  • 115
  • 9
  • You want dashboard `localhost:5556` to be accessible at `localhost/flower-dashboard`? – Anton Mar 18 '23 at 07:04
  • @Anton yes, precisely! – Ishaan007 Mar 18 '23 at 07:15
  • Does this answer your question? [How to forward FastAPI requests to another server?](https://stackoverflow.com/questions/74555102/how-to-forward-fastapi-requests-to-another-server) – Chris Mar 18 '23 at 07:54

1 Answers1

1

This may not be an easy thing to do. To map localhost:5556 to localhost/flower-dashboard you'd need to use a proxy. You could add an Nginx or Apache service to your docker-compose configuration and make it route localhost/flower-dashboard requests to the dashboard service and all other requests localhost/* to the web service. This implies that you do not map web port 80 to the host like you do now, and map the proxy port 80 instead.

Anton
  • 1,793
  • 10
  • 20