Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RuntimeWarning:You're running the worker with superuser privileges:this is absolutely not recommended

Tags:

redis

celery

I am using django+celery+redis,celery==4.4.0 in local it is working fine but when I am dockerizing it , I am getting the above error.

I am using following commands to run in local as well as inside container

**CMDs**
celery -A nrn worker -l info 
docker run -d -p 6379:6379 redis
flower -A nrn --port=5555

Any help is highly appreciated

*settings.py**

CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'

CELERY_BROKER_URL = os.environ.get('redis', 'redis://127.0.0.1:6379/')
like image 904
Pragyan Avatar asked Jan 08 '20 17:01

Pragyan


1 Answers

Take a look in the documentation. It's a warning, though, not an error (see the code). Running Celery under root is an error only when you allow pickle serialization which is not enabled by default (see here).

However, it's still the best practice to run Celery with lower privileges. In Docker (with Debian based image), I choose to run Celery under nobody:nogroup. I use this Dockerfile:

FROM python:3.6

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

WORKDIR /srv/celery

COPY ./app app
COPY ./requirements.txt /tmp/requirements.txt
COPY ./celery.sh celery.sh

RUN pip install --no-cache-dir \
    -r /tmp/requirements.txt

VOLUME ["/var/log/celery", "/var/run/celery"]

CMD ["./celery.sh"]

where celery.sh looks as follows:

#!/usr/bin/env bash

mkdir -p /var/run/celery /var/log/celery
chown -R nobody:nogroup /var/run/celery /var/log/celery

exec celery --app=app worker \
            --loglevel=INFO --logfile=/var/log/celery/worker-example.log \
            --statedb=/var/run/celery/worker-example@%h.state \
            --hostname=worker-example@%h \
            --queues=celery.example -O fair \
            --uid=nobody --gid=nogroup
like image 174
Tomáš Linhart Avatar answered Nov 12 '22 22:11

Tomáš Linhart