Я пытаюсь создать задачу cron в контейнере докера. Все настроено в соответствии с ответом @VonC
Мой файл докеров выглядит так
FROM python:3.6.9FROM python:3.6.9
WORKDIR usr/src/mydir
COPY requirements.txt .
# Add crontab file in the cron directory
ADD crontab /etc/cron.d/hello-cron
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/hello-cron
# Create the log file to be able to run tail
RUN touch /var/log/cron.log
#Install Cron
RUN apt-get update
RUN apt-get -y install cron
# Run the command on container startup
CMD cron && tail -f /var/log/cron.log
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
Но служба cron не запускается по умолчанию
[FAIL] cron is not running ... failed!
служба cron начинает работу после ее явного нажатия из контейнер
service cron start
что не так?
Вы были близки, вот модифицированный файл Docker, который не выдает ошибки и запускает cron:
FROM python:3.6.9
# Add crontab file in the cron directory
ADD crontab /etc/cron.d/hello-cron
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/hello-cron
#Install Cron
RUN apt-get update
RUN apt-get -y install cron
# Create the log file to be able to run tail
RUN touch /var/log/cron.log
# Run the command on container startup
CMD /etc/init.d/cron start && tail -f /var/log/cron.log
Сказав, что этот файл Docker подойдет, если вы тестируете воду. Тем не менее, чтобы запустить что-то в продакшене, вы можете изучить, как сервисы связаны с образами докеров (используйте exec и т. д.)
.