Errno 13 权限被拒绝:Docker + Celery Beat 中的 '/app/celerybeat.pid'
Errno 13 Permission denied: '/app/celerybeat.pid' in Docker + Celery Beat
Celery Beat 在我尝试 运行 docker 容器时导致权限错误。这是因为 Docker 文件中的用户权限,所以我似乎在那里配置了错误。我尝试了所有可能的解决方案,但错误仍然出现。请帮我弄清楚我做错了什么。谢谢。
这是 Docker 文件:
FROM python:3.7-alpine
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache postgresql-client jpeg-dev
RUN apk add --update --no-cache --virtual .tmp-build-deps \
gcc libc-dev linux-headers postgresql-dev musl-dev zlib zlib-dev
RUN pip install -r /requirements.txt
RUN apk del .tmp-build-deps
RUN mkdir /app
COPY ./app /app
WORKDIR /app
RUN adduser -D appuser
RUN chown -R appuser:appuser /app
RUN chmod -R 755 /app/staticfiles
USER appuser
和docker-撰写文件:
version: '3'
services:
app:
build:
context: .
env_file:
- ./.env.dev
volumes:
- ./app:/app
- static_volume_app:/app/staticfiles
- media_volume_app:/app/media
command: >
sh -c "python3 manage.py migrate &&
python3 manage.py wait_for_db &&
gunicorn app.wsgi:application --bind 0.0.0.0:8000"
expose:
- "8000"
depends_on:
- db
db:
image: postgres:10-alpine
env_file:
- ./.env.dev
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
redis:
image: redis:alpine
celery:
restart: always
build:
context: .
command: celery -A app worker -l info
volumes:
- ./app:/app
env_file:
- ./.env.dev
depends_on:
- db
- redis
- app
celery-beat:
build:
context: .
command: celery -A app beat -l info
volumes:
- ./app:/app
env_file:
- ./.env.dev
depends_on:
- db
- redis
- app
nginx:
restart: always
build:
context: .
dockerfile: ./nginx/Dockerfile
volumes:
- static_volume_app:/app/staticfiles
- media_volume_app:/app/media
ports:
- "80:80"
depends_on:
- app
volumes:
pgdata:
static_volume_app:
media_volume_app:
和完整的错误信息:
celery.platforms.LockFailed: [Errno 13] Permission denied: '/app/celerybeat.pid'
当我评论 Docker 文件中的最后 4 行(用户配置)时,它工作正常。
实际上,它通过更改 celery beat 服务中的用户来工作:
celery-beat:
build:
context: .
user: root
command: celery -A app beat -l info
volumes:
- ./app:/app
env_file:
- ./.env.dev
depends_on:
- db
- redis
- app
Celery Beat 在我尝试 运行 docker 容器时导致权限错误。这是因为 Docker 文件中的用户权限,所以我似乎在那里配置了错误。我尝试了所有可能的解决方案,但错误仍然出现。请帮我弄清楚我做错了什么。谢谢。
这是 Docker 文件:
FROM python:3.7-alpine
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache postgresql-client jpeg-dev
RUN apk add --update --no-cache --virtual .tmp-build-deps \
gcc libc-dev linux-headers postgresql-dev musl-dev zlib zlib-dev
RUN pip install -r /requirements.txt
RUN apk del .tmp-build-deps
RUN mkdir /app
COPY ./app /app
WORKDIR /app
RUN adduser -D appuser
RUN chown -R appuser:appuser /app
RUN chmod -R 755 /app/staticfiles
USER appuser
和docker-撰写文件:
version: '3'
services:
app:
build:
context: .
env_file:
- ./.env.dev
volumes:
- ./app:/app
- static_volume_app:/app/staticfiles
- media_volume_app:/app/media
command: >
sh -c "python3 manage.py migrate &&
python3 manage.py wait_for_db &&
gunicorn app.wsgi:application --bind 0.0.0.0:8000"
expose:
- "8000"
depends_on:
- db
db:
image: postgres:10-alpine
env_file:
- ./.env.dev
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
redis:
image: redis:alpine
celery:
restart: always
build:
context: .
command: celery -A app worker -l info
volumes:
- ./app:/app
env_file:
- ./.env.dev
depends_on:
- db
- redis
- app
celery-beat:
build:
context: .
command: celery -A app beat -l info
volumes:
- ./app:/app
env_file:
- ./.env.dev
depends_on:
- db
- redis
- app
nginx:
restart: always
build:
context: .
dockerfile: ./nginx/Dockerfile
volumes:
- static_volume_app:/app/staticfiles
- media_volume_app:/app/media
ports:
- "80:80"
depends_on:
- app
volumes:
pgdata:
static_volume_app:
media_volume_app:
和完整的错误信息:
celery.platforms.LockFailed: [Errno 13] Permission denied: '/app/celerybeat.pid'
当我评论 Docker 文件中的最后 4 行(用户配置)时,它工作正常。
实际上,它通过更改 celery beat 服务中的用户来工作:
celery-beat:
build:
context: .
user: root
command: celery -A app beat -l info
volumes:
- ./app:/app
env_file:
- ./.env.dev
depends_on:
- db
- redis
- app