我在本地使用 django+celery+redis,celery==4.4.0 它工作正常,但是当我对其进行 dockerizing 时,我收到上述错误。
我使用以下命令在本地以及容器内运行
**CMDs**
celery -A nrn worker -l info
docker run -d -p 6379:6379 redis
flower -A nrn --port=5555
非常感谢任何帮助
*设置.py**
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_BROKER_URL = os.environ.get('redis', 'redis://127.0.0.1:6379/')
看看文档 https://docs.celeryproject.org/en/latest/userguide/daemonizing.html#running-the-worker-with-superuser-privileges-root。不过,这是一个警告,而不是错误(请参阅code https://github.com/celery/celery/blob/master/celery/platforms.py#L789)。仅当您允许默认情况下未启用的 pickle 序列化时,在 root 下运行 Celery 才会出现错误(请参阅here http://docs.celeryproject.org/en/master/userguide/configuration.html#accept-content).
然而,以较低权限运行 Celery 仍然是最佳实践。在 Docker(带有基于 Debian 的镜像)中,我选择在下面运行 Celerynobody
:nogroup
。我用这个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
看起来如下:
#!/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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)