Now most of the Docker images are based on Debian # cat /etc/issue Debian GNU/Linux 9 \n \l Docker containers do not support background services. Background services such as systemctl service crontab cannot be accessed through To implement a solution like this, you must write your own entrypoint script to start it. This article records how to set up scheduled tasks in a Debian-based Docker container. Case Background I deployed a front-end project and used the nginx image. Since the official image is based on Debian, the size is not much different compared to Alpine, so I used Debian as the container system. The 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 It's probably about installing cron, then replacing nginx config, then copying our static files, and finally starting nginx and starting cron. Let me tell you why there are timed tasks. You can see that we have a scheduled cleanup script. Since nginx itself does not provide a log processing module, there is a cleanup script. The cleanup script needs to be executed regularly, so there is a scheduled task, and then it is found that the docker container does not support service. In general, there are several steps: install add to crontab Start cron when docker starts ps, many people still prefer alpine as the image matrix because it is small. But this Linux command is indeed unfamiliar. Summarize The above is what I introduced to you about adding crontab scheduled tasks to Debian Docker containers. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: MySQL 8.0.11 installation and configuration method graphic tutorial
>>: Summary of 7 pitfalls when using react
Remax is an open source framework developed by An...
Table of contents Supports multiple types of filt...
Table of contents Docker Installation Nvidia-dock...
The machines in our LAN can access the external n...
The biggest bottleneck of using zabbix is the d...
Prerequisites A cloud server (centOS of Alibaba C...
I'm playing with big data recently. A friend ...
background: As a DBA, most of the DDL changes of ...
Table of contents Case Context switching overhead...
introduce A chart is a graphical representation o...
Running Docker requires root privileges. To solve...
When I first came into contact with HTML, I alway...
This article describes how to install lamp-php7.0...
Detailed tutorial on downloading and installing M...
Preface During development, we often encounter va...