In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to add crontab timing tasks to debian's docker container. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Now most docke images are based on debian
# cat / etc/issueDebian GNU/Linux 9\ n\ l
The Docker container does not support background services, and services such as systemctl service crontab that run in the background cannot pass through the
RUN systemctl start nginx
Similar to this scheme, you have to write your own entrypoint script to start. This article records how the Debian-based docker container sets up scheduled tasks.
Case background
I deployed a front-end project to use the nginx image. Since the official image is based on debian and does not feel much different in size compared to alpine, I use debian as the container system.
Dockerfile looks like this.
FROM nginx:1.15.10MAINTAINER Ryan MiaoCOPY sources.list / etc/apt/sources.listRUN 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.confADD default.conf / etc/nginx/conf.d/ADD index.html / data/web/ADD clean_log.sh / data/COPY clean-cron / etc/cron.d/clean-cronRUN chmod 755 / data/clean_log.sh & & crontab / Etc/cron.d/clean-cronENTRYPOINT nginx & cron & & / bin/bash
Probably just install cron, then replace nginx config, then copy our static file, and finally start nginx and start cron.
Tell me why there are scheduled tasks. You can see that we have a regular cleaning script, because nginx itself does not provide a log processing module, so there is a cleaning script. The cleanup script needs to be executed regularly, so there are scheduled tasks, and it is found that the docker container does not support service.
In general, there are the following steps:
Install
Apt-get install cron
Add to crontab
Crontab / etc/cron.d/your-crontab
Start cron when docker starts
ENTRYPOINT cron & & xxxxx
This is the end of this article on "how to add crontab scheduled tasks to debian's docker container". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.