Skip to content

Latest commit

 

History

History
60 lines (40 loc) · 1.52 KB

cron.md

File metadata and controls

60 lines (40 loc) · 1.52 KB

With Cron Jobs

Note: If you have not checked the basic usage, I recommend that you click here

This document will show you how to use with custom Cron Jobs.

First, you just need to create a cronjob file in your project root.

touch cronjob

Tips: Optionally though, you can put the cronjob file inside the resources directory in Laravel... I think it looks cleaner if you do that.

Then in that file you can put your custom cron command there..

We already defined a default cron to run the laravel schedule command

* * * * * cd /var/www/html && php artisan schedule:run >> /var/log/cron.log 2>&1

if you need to do something else,

just write that command in the cronjob file you just created along with your new command as follows

* * * * * cd /var/www/html && php artisan schedule:run >> /var/log/cron.log 2>&1
# your new command below

Example:

* * * * * cd /var/www/html && php artisan schedule:run >> /var/log/cron.log 2>&1
# your new command below
* * * * * cd /var/www/html && php artisan custom:command >> /var/log/cron.log 2>&1

and then add this line in your Dockerfile

COPY ./cronjob /etc/cron.d/app_cron
RUN chmod 644 /etc/cron.d/app_cron
RUN crontab /etc/cron.d/app_cron

In the end, your Dockerfile should look like this:

FROM wendyourway/laravel-docker:latest
LABEL maintainer Mark <[email protected]>

COPY . /var/www/html

COPY ./cronjob /etc/cron.d/app_cron
RUN chmod 644 /etc/cron.d/app_cron
RUN crontab /etc/cron.d/app_cron