Home > Software design >  run cronjob and supervisor in dockerfile
run cronjob and supervisor in dockerfile

Time:01-18

I am new to docker and trying to run supervisor and corn , but in this file it is just running supervisor. I know the problem is with last line but how can I fix it?

FROM php:7.4-fpm

# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/

# Set working directory
WORKDIR /var/www

# Install dependencies
RUN apt-get update && apt-get install -y \
    libonig-dev\
    build-essential \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    unzip \
    git \
    curl \
    libzip-dev

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN apt-get update
RUN apt-get update && apt-get install -y cron

COPY /docker/crontab /etc/cron.d/crontab
#
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/crontab
RUN crontab /etc/cron.d/crontab

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


RUN apt-get update && apt-get install -y supervisor
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf


CMD /usr/bin/supervisord ; cron && tail -f /var/log/cron.log

CodePudding user response:

Because you are using ";" after the supervisor. So the command waits for supervisor the finish and after that cron will run. You can make it like:

CMD /usr/bin/supervisord & cron && tail -f /var/log/cron.log

so the supervisor will run in the back ground. Or if you want container the fail if supervisor fails you can do it like:

CMD cron && tail -f /var/log/cron.log  & /usr/bin/supervisord 
  •  Tags:  
  • Related