Errno 13 Permission denied: ‘/app/celerybeat.pid’ in Docker + Celery Beat

  celerybeat, django, django-celery, docker, docker-compose

Celery Beat causes permission error when I try to run the docker containers. This is because the user permissions in Docker file so it seems I configured something wrong there. I tried all possible solutions but the error still showing up. Please help me to figure out what am I doing wrong. Thank you.

Here is the Docker file:

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

and docker-compose file:

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:

and full error message:

celery.platforms.LockFailed: [Errno 13] Permission denied: '/app/celerybeat.pid'

When I comment the last 4 lines in Docker file which is user configurations it works fine.

Source: Docker Questions

LEAVE A COMMENT