My goal is to run a Docker container that contains crontab, so. So I want, as a non-root user, to be able to run scheduled crontab jobs. I am running the following Docker image:
FROM openjdk:8
RUN apt-get update && apt-get -y install nano
RUN apt-get update && apt-get -y install cron
RUN service cron start # tried both
RUN cron # tried both
ENV TZ="Europe/Rome"
RUN useradd -u 8877 myuser
USER myuser
CMD ["tail", "-f", "/dev/null"]
I deploy it in a Docker stack:
...
crontab:
image: reg/image
cap_drop:
- cap_dac_override
deploy:
mode: replicated
replicas: 1
restart_policy:
condition: any
delay: 3s
window: 60s
placement:
constraints: [node.role == manager]
update_config:
delay: 2s
volumes:
- v:/my/vol
environment:
- PUID=8877
- PGID=8877
...
When I run docker exec -it <id> bash as myuser into the container, I execute service cron status and it outputs "cron is running." But if I try torun crontab -e, the file I am writing appears with the red error message "Problems with history file". If I try to save it, others errors appear, such as "no crontab for myuser - using an empty one
touch: cannot touch '/home/myuser/.selected_editor': No such file or directory
Unable to create directory /home/myuser/.local/share/nano/: No such file or directory
It is required for saving/loading search history or cursor positions."