Celery not working when running in Docker container
Clash Royale CLAN TAG#URR8PPP
Celery not working when running in Docker container
I am trying to develop an application which is composed of a listener which sends events to RabbitMQ, which Celery extracts from a queue.
When running all the components locally my application works as expected. It also works if my listener is running locally, and all the other components are running in Docker containers. But if I also run my listener in a container then Celery does not receive any events.
The application is based on Django and the connection to Celery is done like this:
app = Celery('mini_iot')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
And in settings.py I have:
CELERY_BROKER_URL = 'amqp://rabbitmq'
Where rabbitmq is the hostname of the container.
The listener sends tasks to Celery using the delay
function.
delay
The docker-compose is:
version: '3'
services:
listener:
image: core-app
command: python manage.py runscript listener
volumes:
- .:/mini-iot
depends_on:
- rabbitmq
- mqtt
working_dir: /mini-iot/mini_iot
worker:
image: core-app
command: celery -A mini_iot worker --loglevel=info -f log2.txt
volumes:
- .:/mini-iot
depends_on:
- rabbitmq
- mqtt
working_dir: /mini-iot/mini_iot
rabbitmq:
image: rabbitmq:3.6.10
volumes:
- /var/lib/rabbitmq:/var/lib/rabbitmq
ports:
- "5672:5672"
- "15672:15672"
Can anyone help me debug the problem or does anyone have an idea about what the problem is?
The containers can communicate with each other on the correct ports. I have tested using telnet.
Thanks, I updated the question
– Alexandra
Aug 8 at 6:20
Any error messages ?
– JPG
Aug 8 at 7:51
No error message appears
– Alexandra
Aug 8 at 8:07
2 Answers
2
you should add links to both listener
& worker
:
listener
worker
version: '3'
services:
listener:
image: core-app
command: python manage.py runscript listener
volumes:
- .:/mini-iot
links:
- rabbitmq
depends_on:
- rabbitmq
- mqtt
working_dir: /mini-iot/mini_iot
worker:
image: core-app
command: celery -A mini_iot worker --loglevel=info -f log2.txt
volumes:
- .:/mini-iot
links:
- rabbitmq
depends_on:
- rabbitmq
- mqtt
working_dir: /mini-iot/mini_iot
rabbitmq:
image: rabbitmq:3.6.10
volumes:
- /var/lib/rabbitmq:/var/lib/rabbitmq
ports:
- "5672:5672"
- "15672:15672"
I think your CELERY_BROKER_URL should be
amqp://guest:guest@rabbitmq:5672
amqp://guest:guest@rabbitmq:5672
According the the rabbitmq docker docs (https://hub.docker.com/_/rabbitmq/), the default username and password are guest/guest.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
The description of the docker setup is necessary, so people can help. Stuff like the network configuration of the containers is essential for this case.
– dethos
Aug 7 at 21:38