Cronjob to run a PHP script not working

Hi,

I want to write a Dockerfile with cronjob that will schedule a PHP script run.
The Dockerfile is:

FROM php:7.4-apache

# Install dependencies
RUN apt-get update && apt-get install -y cron

# Copy PHP script and other necessary files
COPY script.php /var/www/html/script.php

# Create crontab file
RUN echo "* * * * * php /var/www/html/script.php" > /etc/cron.d/my-cron

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/my-cron

# Apply cron job
RUN crontab /etc/cron.d/my-cron

# Run the command on container startup
CMD cron && apache2-foreground

And the PHP script is simple:

<?php
echo 'blah';

Now I am building and running the image from the terminal. I am not running in detach mode so I should see ‘blah’ every minute. However, it is not working.
Can anyone explain to me why it isn’t working?

Hi

I do belive your script is being run, but cron dosnt show you the output of scripts running in cron