Ang*_*eal 12 python django permissions celery docker
我有一个 Django (2.1.2) Docker 项目,我尝试包含 Celery (4.2.1),由于权限错误,它最终会退出 0。
docker-compose.yml
...
celery:
build: .
command: celery worker -A core --workdir /opt/services/web_app/src -l info
volumes:
- .:/opt/services/web_app/src
depends_on:
- database1
- redis
Run Code Online (Sandbox Code Playgroud)
在我使用“docker-compose build”构建然后运行“docker-compose up”后,我收到此错误消息:
celery_1 | /usr/local/lib/python3.7/site-packages/celery/platforms.py:796:
celery_1 | RuntimeWarning: You're running the worker with superuser privileges: this
celery_1 | is absolutely not recommended!
celery_1 |
celery_1 | Please specify a different user using the --uid option
Run Code Online (Sandbox Code Playgroud)
所以..我什至不知道 Docker 有“用户”,所以我在公开之前将它添加到底部的“Dockerfile”中。
...
RUN groupadd -g 999 celery && \
useradd -r -u 999 -g celery celery
USER celery
EXPOSE 8000
Run Code Online (Sandbox Code Playgroud)
然后使用用户更新“Dockerfile”:
...
celery:
build: .
command: celery worker -A core --workdir /opt/services/web_app/src -l info --uid=celery
volumes:
- .:/opt/services/web_app/src
depends_on:
- database1
- redis
Run Code Online (Sandbox Code Playgroud)
当我现在运行它时,我收到错误消息:
celery_1 | File "/usr/local/lib/python3.7/site-packages/celery/platforms.py", line 502,
celery_1 | in initgroups return os.initgroups(username, gid)
celery_1 | PermissionError: [Errno 1] Operation not permitted
Run Code Online (Sandbox Code Playgroud)
uid,请使用该multi命令,而不是,并以 root 身份worker运行该命令。multi如果您想使用,worker只需运行不带uid.1如果这只是为了本地开发,您还可以将 C_FORCE_ROOT 环境变量设置为并在 docker 中以 root 身份运行。注意,您可能还需要更新文件权限,以防您的 celery 任务向文件系统写入任何内容(例如日志文件或临时文件)。
| 归档时间: |
|
| 查看次数: |
5947 次 |
| 最近记录: |