Debian added to the container docker regular tasks crontab

Now most of the docke image is based on debian

# cat /etc/issue
Debian GNU/Linux 9 \n \l

Docker container does not support background services, services like these systemctl service crontab is running in the background can not be

RUN systemctl start nginx

Similar programs to achieve this, you have to write your own script to start entrypoint. This paper records the set time of the task-based Debian docker container manner.

Case Background

I deployed a front-end project, using nginx mirror, because the mirror is based on the official debian, contrast alpine volume do not feel much worse, so I use debian as a container system.

Dockerfile looks like this

FROM nginx:1.15.10
MAINTAINER Ryan Miao 

COPY sources.list   /etc/apt/sources.list
RUN apt-get update  && apt-get install -y net-tools procps curl wget vim telnet cron 、
    && apt-get autoremove && apt-get clean && rm -rf /var/lib/apt/lists/*

RUN mkdir -p /data/log/nginx  && mkdir -p /data/web && rm /etc/nginx/conf.d/default.conf
ADD default.conf /etc/nginx/conf.d/
ADD index.html  /data/web/

ADD clean_log.sh /data/
COPY clean-cron /etc/cron.d/clean-cron
RUN chmod 755 /data/clean_log.sh && crontab /etc/cron.d/clean-cron

ENTRYPOINT nginx && cron &&  /bin/bash

Probably install cron, then replace nginx config, then copy our static files, last start nginx, start cron.

Talk about why there is a scheduled task. We can see that there is a regular cleaning of the script because they did not provide nginx log processing module, so only clean-up script. It requires regular clean-up script execution, so there will be regular tasks, then find docker container does not support the service.

Overall, a total of the following steps:

install

apt-get install cron

add to crontab

crontab /etc/cron.d/your-crontab

Start cron start when docker

ENTRYPOINT cron && xxxxx

ps, many people still prefer alpine mirrored the mother, because of the small. But this does not familiar with the Linux command.

Guess you like

Origin www.cnblogs.com/woshimrf/p/docker-debian-crontab-install.html