Docker Community Forums

Share and learn in the Docker community.

Cron as Docker Container, everything is not found

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

It is started from docker-comopse

    build: './cron/'
    container_name: qnap_cron
    hostname: qnap_cron
        - /share/:/share/
        - /share/config/perm/cron/
        - CRON_LOGLEVEL=7
        - backend
    restart: always

set -e
echo "$1" | crontab / && crond -f -L /dev/stdout -l $CRON_LOGLEVEL

My goal is to start this script with (for testing purpose 1min)

*       *       *       *       *       /share/config/scripts/

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/ not found
crond: USER root pid  77 cmd /share/config/scripts/

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' > /

in order to change the to

    *       *       *       *       *       . /; pwd

but again

crond: USER root pid  78 cmd . /; pwd
/bin/ash: pwd
: not found

At least I added this

* * * * * env > /env.output

Which leads to


The normal env output is


For testing I added in docker-compose

            - TERM=xterm

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.

Do you see this file in the container and is it executable?
And it’s more secure to write the full path to the commands in cron, you can never be sure which part of the environment is available.

Yes, I see the file and it is executable.

/ # ls -la /share/config/scripts/
-rwxrwxrwx    1 1000     users          658 Jun  8 08:12 /share/config/scripts/

The “full-path-problem” should be solved with “. /” (see above) if I understand it right. It seems for me, that commands like “. /” or “source ./” are not parsed and perhaps the from Docker mounted volume ("/share") is not available in cron.

FUCK. Nearly a whole day before I realized that working on with nano in the console leads to symbols on line ending which are not displayed (in nano).

nano displays

*       *       *       *       *       /share/config/scripts/

the same file opened with vi displays

*       *       *       *       *       /share/config/scripts/^M

After deleting the “^M” at the end on the line with vi it works. Now I have to clean my upchucked keyboard…