How to run Laravel Scheduled Task using Docker

I have laravel project that need to update employees used leaves and remaining leaves on every year begin. So I have created scheduled task to run on every year begin. Also tested it in local setup by executing php artisan schedule:run command. It worked properly, database get updated. As running artisan commands risky in production environment I’ve asked to try to run that cronjob using docker.
There’s the issue comes.

After create the docker image and run the container, cronjob is not working. Database didn’t get update, which means artisan command not executing. I have no idea where the issue comse from because when runservice cron status on container CLI it shows cron running.

Senior developer had created dockerfile already. After going through some youtube videos and articles I did some changes for dcokerfile, I will mention that below. As I’m not familiar with docker I can’t figure out the issue, why does cronjob not working properly. I would be very thankful if anyone could point out the issue or how to do this. I have no idea how to set the paths. If you could share your knowledge with me, I’ll be very grateful.

This is my crontab file

* * * * * /usr/local/bin/php /var/www/artisan schedule:run >> /my-log.txt 2>&1
# Don’t remove the empty line at the end of this file. It is required to run the cron job

This is the docker file

# Use the official PHP image as base
FROM php:8.2-apache

# Enable Apache ModRewrite
RUN a2enmod rewrite

# Install required system packages
RUN apt-get update 
    && apt-get install -y --no-install-recommends 
        libz-dev 
        libpq-dev 
        libjpeg-dev 
        libpng-dev 
        libssl-dev 
        libzip-dev 
        unzip 
        zip 
    && apt-get clean 
    && docker-php-ext-configure gd 
    && docker-php-ext-configure zip 
    && docker-php-ext-install 
        gd 
        exif 
        opcache 
        pdo_mysql 
        pdo_pgsql 
        pgsql 
        pcntl 
        zip 
    && rm -rf /var/lib/apt/lists/*;

# Install cron
RUN apt-get update && apt-get -y install cron 
    && apt-get clean;

# Enable SSL module
RUN a2enmod ssl

# Copy SSL certificate and key into the container
COPY ./docker/fullchain.pem /etc/ssl/certs/fullchain.pem
COPY ./docker/privkey.pem /etc/ssl/private/privkey.pem

# Copy custom Apache configuration file
COPY ./docker/laravel_ssl.conf /etc/apache2/sites-available/laravel_ssl.conf

# Enable the new site
RUN a2ensite laravel_ssl

# Restart Apache to apply changes
RUN service apache2 restart

RUN rm -rf /var/www/html/*

# Set the working directory in the container
# WORKDIR /var/www/html

# Copy the Laravel application files into the container
COPY . .

# Install Composer and dependencies
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer install --no-dev --optimize-autoloader

# Update Apache document root to point to the public directory
RUN sed -ri -e 's!/var/www/html!/var/www/html/public!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!/var/www/html/public!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

# Expose ports for HTTP and HTTPS
ENV APP_KEY=base64:MaRBFYRnBPBD1VP2SAYqYBGoOmgy5dlB23lygXKRTb8=
ENV DB_CONNECTION=mysql
ENV DB_HOST=127.0.0.1
ENV DB_PORT=3306
ENV DB_DATABASE=evicio_hrm
ENV DB_USERNAME=root
ENV DB_PASSWORD=
ENV APP_DEBUG=true
# Expose port 80 to the outside world
EXPOSE 80
EXPOSE 443

# Copy crontab file in the cron directory
COPY cronfile /etc/cron.d/cronfile

#Give execution rights on cron job
RUN chmod 0644 /etc/cron.d/cronfile

# Apply the cron job
RUN crontab /etc/cron.d/cronfile

# Create the log file to be able to run tail
RUN touch /var/log/cron.log
RUN chmod 0666 /var/log/cron.log

# Start Apache when the container starts
CMD ["sh", "-c", "service cron start && apache2-foreground"]

## Set folder perirmissions
RUN chmod -R 777 /var/www/html/bootstrap/cache/ 
    && chmod -R 777 /var/www/html/storage/

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật