Answer the question
In order to leave comments, you need to log in
Docker, CRON /bin/sh: 1: Syntax error: Bad fd number What's wrong?
Tell me what am I doing wrong?
Trying to run cron in docker image php
Dockerfile:
FROM php:7-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzip-dev \
zip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install zip \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install pdo_mysql
# Install cron
RUN apt-get update && apt-get install -y cron \
nano
COPY cronfile /etc/cron.d/cronfile
RUN chmod 0644 /etc/cron.d/cronfile && \
touch /var/log/cron.log && \
chmod 0777 /var/log/cron.log && \
crontab /etc/cron.d/cronfile
CMD bash -c "cron && php-fpm"
* * * * * echo "Hello world" >> /var/log/cron.log 2>&1
# An empty line is required at the end of this file for a valid cron file.
/bin/sh: 1: Syntax error: Bad fd number
SHELL=/bin/bash
/bin/bash: 1
: ambiguous redirect
Answer the question
In order to leave comments, you need to log in
Resolved the issue. Maybe someone will help. If I create a cronfile in windows, some character is added to the beginning of the file, which is not readable by sh.
If you create a task file through the console, then everything will be fine.
I managed this way:
FROM php:7-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzip-dev \
zip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install zip \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install pdo_mysql
# Install cron
RUN apt-get update && apt-get install -y cron \
nano
RUN touch /etc/cron.d/cronfile && \
touch /var/log/cron.log && \
echo "SHELL=/bin/sh" >> /etc/cron.d/cronfile && \
echo "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" >> /etc/cron.d/cronfile && \
echo "* * * * * echo 777555 >> /var/log/cron.log 2>&1" >> /etc/cron.d/cronfile && \
chmod 0644 /etc/cron.d/cronfile && \
chmod 0777 /var/log/cron.log && \
crontab /etc/cron.d/cronfile
CMD cron && php-fpm
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question