I have a problem with cron in a docker container. Everything I want to start is not being found. I have searched much about this but I only found rather old threads so I decided to add a new one.
I want to have a docker container with running crond on my QNAP TS453pro.
My dockerfile is
FROM alpine COPY ENTRYPOINT.sh /ENTRYPOINT.sh ENTRYPOINT ["/ENTRYPOINT.sh"]
It is started from docker-comopse
cron: build: './cron/' container_name: qnap_cron hostname: qnap_cron volumes: - /share/:/share/ - /share/config/perm/cron/CRONJOBS.sh:/CRONJOBS.sh environment: - CRON_LOGLEVEL=7 networks: - backend restart: always
#!/bin/sh set -e echo "$1" | crontab /CRONJOBS.sh && crond -f -L /dev/stdout -l $CRON_LOGLEVEL
My goal is to start this script with CRONJOBS.sh (for testing purpose 1min)
* * * * * /share/config/scripts/_cron_1min.sh
cron starts fine but end with error while executing the script
Pseudo-terminal will not be allocated because stdin is not a terminal. crond: crond (busybox 1.29.3) started, log level 7 /bin/ash: /share/config/scripts/_cron_1min.sh: not found crond: USER root pid 77 cmd /share/config/scripts/_cron_1min.sh
So I tried to simplify the command.
* * * * * pwd
crond: USER root pid 76 cmd pwd
/bin/ash: pwd : not found
I found various posts that the shell of cron has not much env variables so I add this line to dockerfile
RUN printenv | sed 's/^\(.*\)$/export \1/g' > /ENV.sh
in order to change the CRONJOBS.sh to
* * * * * . /ENV.sh; pwd
crond: USER root pid 78 cmd . /ENV.sh; pwd /bin/ash: pwd : not found
At least I added this CRONJOBS.sh
* * * * * env > /env.output
Which leads to
USER=root HOSTNAME=qnap_cron SHLVL=2 HOME=/root CRON_LOGLEVEL=7 LOGNAME=root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin SHELL=/bin/ash PWD=/root
The normal env output is
HOSTNAME=qnap_cron PWD=/ HOME=/root TERM=xterm SHLVL=1 CRON_LOGLEVEL=7 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin _=/usr/bin/env
For testing I added in docker-compose
to have the same environment. But again always is everything not found except
env > /env.output
For everyone who reads up to here many thanks. Accordingly to the output it must be as user root under /bin/ash. Every command works as user root on the shell without cron. If anyone has a tip for me I would be very glad about. I really do not get the reason. Please help me.