Sel*_*ali 6 cron laravel docker
我有一个容器,用于我的 Laravel 应用程序,其中 php:7.0.4-fpm 作为基本图像。
这是我的 dockerfile :
FROM php:7.0.4-fpm
RUN apt-get update && apt-get install -y cron nano libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install mcrypt pdo_mysql
COPY . /var/www
ADD crontab /etc/cron.d/laravel-cron
RUN chmod 0644 /etc/cron.d/laravel-cron
RUN touch /var/log/cron.log
RUN /usr/bin/crontab /etc/cron.d/laravel-cron
RUN cron
Run Code Online (Sandbox Code Playgroud)
当我手动启动它时,它适用于一些简单的事情,比如每分钟回显一个文本。但不适用于php artisan schedule:run命令。在日志中我看到:
运行预定命令:'/usr/local/bin/php' 'artisan' 错误:插入 > '/dev/null' 2>&1
错误:插入是我的任务名称,但网站中没有任何更新。
所以我的问题是:如何让 cron 在 docker 容器上运行以执行 php artisan schedule:run 命令?最好用 dockerfile 编写,而不是通过 ssh 手动编写。
我也收到了来自容器的奇怪消息:
ALERT: oops, unknown child (5094) exited with code 1.
Please open a bug report (https://bugs.php.net).
Run Code Online (Sandbox Code Playgroud)
小智 10
另一种解决方案是php artisan schedule:run
与主管一起运行。就我而言,我在[项目根]/.docker/php/workers中有一个schedule-run.conf:
[program:schedule-run]
process_name=%(program_name)s_%(process_num)02d
command=/bin/bash -c "while [ true ]; do (php /var/www/html/artisan
schedule:run --verbose --no-interaction &); sleep 60; done"
autostart=true
autorestart=true
user=root
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/schedule.log
stopwaitsecs=60
Run Code Online (Sandbox Code Playgroud)
apt-get install -y cron
的apt-get install -y supervisor
ADD .docker/php/workers /etc/supervisor/conf.d
将和 添加CMD ["/usr/bin/supervisord"]
到您的 Dockerfile 中。虽然这是一个迟到的回复,但我认为我的解决方案可能会帮助其他人,因为我以前遇到过这个问题。
我创建了单独的 docker 容器作为 Laravel Docker Cron 来执行 laravel 计划
这是我的 Dockerfile 代码
FROM ubuntu:latest
MAINTAINER docker@ekito.fr
ENV DEBIAN_FRONTEND=noninteractive
# install base packages
RUN apt-get update && apt-get -y install cron\
apt-utils \
curl \
# Install php 7.2
php7.2 \
php7.2-cli \
php7.2-json \
php7.2-curl \
php7.2-fpm \
php7.2-dev \
php7.2-gd \
php7.2-ldap \
php7.2-mbstring \
php7.2-bcmath \
php7.2-mysql \
php7.2-soap \
php7.2-sqlite3 \
php7.2-xml \
php7.2-zip \
php7.2-intl \
libldap2-dev \
libaio1 \
libaio-dev
# Install tools
RUN apt-get -y install openssl \
nano \
ghostscript \
iputils-ping \
locales \
rlwrap \
php-pear \
make \
unzip \
zip \
tar \
ca-certificates \
&& apt-get clean &&\
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Set locales
RUN locale-gen en_US.UTF-8 en_GB.UTF-8 de_DE.UTF-8 es_ES.UTF-8 fr_FR.UTF-8 it_IT.UTF-8 km_KH sv_SE.UTF-8 fi_FI.UTF-8
# Copy crontab file to the cron.d directory
COPY crontab /etc/cron.d/crontab
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/crontab
# Apply cron job
RUN crontab /etc/cron.d/crontab
# Create the log file to be able to run tail
RUN touch /var/log/cron.log
# Run the command on container startup
CMD cron && tail -f /var/log/cron.log
Run Code Online (Sandbox Code Playgroud)
crontab 文件将包含
* * * * * cd /var/www && php artisan schedule:run >> /var/log/cron.log 2>&1
# An empty line is required at the end of this file for a valid cron file.
Run Code Online (Sandbox Code Playgroud)
这是此代码的存储库,请单击此处
归档时间: |
|
查看次数: |
4805 次 |
最近记录: |