【发布时间】:2021-05-06 16:49:03
【问题描述】:
我正在使用php:7.4-fpm Docker 映像,我正在尝试设置 cron 以运行但它没有运行。
这是我的 Dockerfile:
FROM php:7.4-fpm
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
cron \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
libzip-dev \
libmcrypt-dev \
libonig-dev \
zlib1g-dev \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
graphviz \
curl \
supervisor
# Install Imagick
RUN apt-get update && \
apt-get install -y libmagickwand-dev --no-install-recommends && \
pecl install imagick && \
docker-php-ext-enable imagick
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql zip exif pcntl
# Permissions for Laravel
RUN chown -R www-data:www-data /var/www
RUN chmod -R 777 /var/www
# Copy crontab file to the cron.d directory
COPY ./docker/php-server/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
EXPOSE 9000
CMD bash -c "cron && php-fpm"
当我进入容器并检查/etc/cron.d/crontab的内容时,它是正确的
* * * * * php /var/www/artisan schedule:run >> /var/log/cron.log 2>&1
# An empty line
但它没有运行。我不确定这里发生了什么..
当我运行service cron status 时,它显示[ ok ] cron is running. 但什么也没有发生。
【问题讨论】:
-
可能复制 Dockerfile 中的 crontab 改变了所有者/组
/etc/cron.d/crontab -
只是一个旁注:而不是
apt-get install和docker-php-ext-install使用github.com/mlocati/docker-php-extension-installer 怎么样?
标签: php docker cron dockerfile containers