Docker Community Forums

Share and learn in the Docker community.

Error while running crontab as non root docker users

I have a centos7 docker container which is running as non root user. I installed cronie and started crond as non root user from the containers entrypoint.sh

entryoint.sh

    #!/bin/bash
    sleep 2h

I login to the container and manually run the crontab in debug mode as

    crond -x ext

My Dockerfile

FROM centos:7
RUN groupadd rsuser -g 10001
RUN useradd -d /home/rsuser -m rsuser -u 10001 -g 10001 -p rsuser
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
RUN yum install -y cronie && yum clean all
RUN touch /var/run/crond.pid
RUN echo '* * * * * root echo "crontab running"' >> /etc/crontab
RUN setcap cap_setgid+ep /usr/sbin/crond && \
    setcap cap_setuid+ep /usr/sbin/crond
RUN chown -R rsuser:rsuser /var/run/crond.pid
RUN chmod 400 /etc/shadow
USER 10001
ENTRYPOINT ["/entrypoint.sh"]

If I run crontab commands as root then I get below error

* * * * * root echo "crontab running"
log_it: (CRON 23) ERROR (setgid failed): Operation not permitted

If I run crontab commands as rsuser then I get below error

* * * * * rsuser echo "crontab running"
log_it: (CRON 23) ERROR (initgroups failed): Operation not permitted

Not finding a way to fix that.

Also posted in linux - Error while running crontab as non root docker users - Stack Overflow.