docker-cron
docker-cron copied to clipboard
using non root user
Hi, thanks for this repo. It's really useful. I have one problem though. I want to use a non-root user in the image. Do you have any idea how this could be done?
I get some error like this:
crond[11]: can't set groups: Operation not permitted
More Info
Dockerfile
FROM python:3.8-alpine
ENV PYTHONPATH /opt/app
RUN rm -rf /etc/periodic
COPY entrypoint.sh /usr/bin/
COPY cronjob /var/spool/cron/crontabs/root
ARG UID=9000
ARG USER=uwsgi
RUN adduser \
--disabled-password \
--gecos "" \
--home ${PYTHONPATH} \
--no-create-home \
--uid ${UID} \
${USER}
RUN touch /etc/environment
RUN chown ${UID}:${UID} /etc/environment
WORKDIR ${PYTHONPATH}
COPY cmd.sh .
USER ${USER}
ENTRYPOINT [ "entrypoint.sh" ]
CMD [ "./cmd.sh" ]
entrypoint.sh
#!/bin/sh
set -ex
env >> /etc/environment
crond -l 2
exec "$@"
cronjob
* * * * * date
cmd.sh
#!/bin/sh
while true;
do
echo "running"
sleep 12
done
Related Links
I found one old question on SO regarding this:
https://stackoverflow.com/questions/53103621/how-to-start-crond-as-non-root-user-in-a-docker-container
I've seen people use this - https://github.com/odise/go-cron