0

I want to make my cron work on docker container. Do you have suggestions to make works my cron setup in my dockerfile. My server is working good, no errors but my cron do nothing. There is my two files, if you need something more, ask me !

Dockerfile at /

FROM node:15 as assets

WORKDIR /app
COPY package*.json /app/
RUN npm install --no-save
COPY . /app
RUN node_modules/.bin/gulp deploy

FROM composer:1.4.1 as vendors
COPY composer.json composer.lock /app/
RUN composer global require hirak/prestissimo \
    && composer install --ignore-platform-reqs --no-dev --no-interaction --no-progress --prefer-dist --no-autoloader --no-scripts
COPY . /app
RUN composer dump-autoload --optimize --classmap-authoritative --no-dev --no-interaction

FROM ubuntu:latest
RUN apt-get update && apt-get -y install cron
COPY cron /etc/cron.d/cron
RUN chmod 0644 /etc/cron.d/cron
RUN crontab /etc/cron.d/cron
RUN touch /var/log/cron.log
CMD cron && tail -f /var/log/cron.log

FROM php:7.2.21-apache as app
LABEL maintainer="dev@wizaplace.com"
RUN apt-get update && apt-get install -y \
    libicu-dev \
    libzip-dev \
    && docker-php-ext-install -j$(nproc) \
    intl \
    zip \
    opcache

COPY . /var/www/html/
COPY --from=vendors /app/vendor/ /var/www/html/vendor
COPY --from=assets /app/web/ /var/www/html/web

RUN a2enmod rewrite headers remoteip \
    && sed -i 's@/var/www/html@/var/www/html/web@' /etc/apache2/sites-available/000-default.conf

RUN { \
    echo 'RemoteIPHeader X-Forwarded-For'; \
    echo 'LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined'; \
    echo '<Location /status>'; \
    echo '  SetHandler server-status'; \
    echo '  Require local'; \
    echo '  Require ip 10.0.0.0/8'; \
    echo '</Location>'; \
    echo 'Alias /status /var/www/status'; \
    } >> "$APACHE_CONFDIR/conf-available/docker-php.conf" && \
    touch /var/www/status && \
    chown www-data:www-data /var/www/status

ENV SYMFONY_ENV "prod"

RUN touch app/config/parameters.yml \
    && php bin/console assets:install \
    && php bin/console fos:js-routing:dump

RUN chown -R www-data:www-data /var/www/html/var /var/www/html/web

EXPOSE 80

cron file at /

* * * * * root echo "Cron active" >> /var/log/cron.log 2>&1
*/5 * * * * php bin/console --env=prod wizaplace:translations:pull && php bin/console --env=prod cache:warmup >/dev/null 2>&1
0 1 * * * php bin/console --env=prod sitemap:generate >/dev/null 2>&1
# tab

1 Answers1

0

Try something like this:

RUN echo "* * * * * root php /var/www/test schedule:run >> /var/log/cron.log 2>&1" >> /etc/crontab

# Create the log file to be able to run tail

RUN touch /var/log/cron.log
Anas Khan
  • 34
  • 5
  • Thanks for your answers, that's correctly add the command in the crontab file in the container but no cron are running still. Have you an idea ? – Yannis Haismann Jul 17 '22 at 13:16
  • Hi @YannisHaismann Please look at the given CMD instruction: https://docs.docker.com/engine/reference/builder/#cmd – Anas Khan Jul 17 '22 at 15:37
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 19 '22 at 12:09