Search code examples
pythondockerdebuggingdocker-composecelery

How to use celery rdb while working with python, flask, docker and docker compose?


I use python, flask, celery, docker and docker compose in my project and wanted to use celery rdb to debug my tasks. I could not connect to celery container using telnet from my local machine to docker container.


Solution

  • I could not find an easy way to do it. Finally I ended up with followings:

    1. install telnet into celery container (add on following Dockerfile )
    # install system dependencies
    RUN apt-get update && apt-get install -y telnet
    
    1. trigger celery task. you will see logs output like this: Remote Debugger:6900: Ready to connect: telnet 127.0.0.1 6900
    2. go into the celery container in another terminal
    docker compose exec my_celery bash
    
    1. run telnet command
    root@fc4dcaa378xy:/usr/src/app# telnet 0.0.0.0 6900
        Trying 0.0.0.0...
        Connected to 0.0.0.0.
        Escape character is '^]'.
        > /usr/src/app/api/tasks.py(55)my_task()
        -> scraper_res = myfunc(url, *args, **kwargs)
        (Pdb) pp locals()