'How to add django-crontab in docker container with user django project
Problem ?
I am using django-crontab. I can't run it as an authorized user on Docker alpine. I get the following error
no crontab for app
adding cronjob: (6e4989c275eb1a7f1e4c58d3442c53fe) -> ('*/1 * * * *', 'core.cron.hello')
initgroups failed: app Operation not permitted
unable to read replacement file /tmp/tmp1ehdmy4i%
Docker File
FROM python:3.9-alpine3.13
LABEL maintainer="mrfk"
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /requirements.txt
COPY ./app /app
COPY ./scripts /scripts
WORKDIR /app
EXPOSE 8000
RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
apk add --update --no-cache postgresql-client && \
apk add --update --no-cache --virtual .tmp-deps \
build-base postgresql-dev musl-dev linux-headers && \
/py/bin/pip install -r /requirements.txt && \
apk del .tmp-deps && \
apk add --update busybox-suid && \
apk --no-cache add dcron libcap && \
adduser --disabled-password --no-create-home app && \
mkdir -p /vol/web/static && \
mkdir -p /vol/web/media && \
chown -R app:app /vol && \
chmod -R 755 /vol && \
chmod -R +x /scripts && \
chmod 755 /usr/bin/crontab*
ENV PATH="/scripts:/py/bin:$PATH"
USER app
CMD ["run.sh"]
Run.SH File
#!/bin/sh
set -e
ls -la /vol/
ls -la /vol/web
whoami
service cron start
python manage.py wait_for_db
python manage.py collectstatic --noinput
python manage.py migrate
uwsgi --socket :9000 --workers 4 --master --enable-threads --module app.wsgi
I'm trying to create a simple cronjob in a django project but I can't solve the user side problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
