-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
68 lines (56 loc) · 1.48 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 使用官方 Python 镜像作为基础镜像
FROM python:3.9-slim
# 设置工作目录
WORKDIR /app
# 将当前目录下的所有文件复制到容器中的工作目录
COPY . /app
# 安装系统依赖
RUN apt-get update && \
apt-get install -y \
wget \
curl \
unzip \
libx11-dev \
libgconf-2-4 \
libnss3 \
libxss1 \
libgdk-pixbuf2.0-0 \
libasound2 \
libxtst6 \
libdrm2 \
libgbm1 \
libvulkan1 \
xdg-utils \
iputils-ping \
cron \
fonts-liberation \
libappindicator3-1 \
libnspr4 \
libnss3-dev \
libxcomposite1 \
libxrandr2 \
libgtk-3-0 \
libdbus-1-3 \
libatspi2.0-0 \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# 安装 Google Chrome
RUN dpkg -i google-chrome-stable_current_amd64.deb || apt-get install -f -y
# 安装 chromedriver
COPY chromedriver /usr/local/bin/chromedriver
RUN chmod +x /usr/local/bin/chromedriver
# 删除本地文件
RUN rm -f google-chrome-stable_current_amd64.deb chromedriver
# 安装 selenium
RUN pip install selenium
# 设置环境变量
ENV CHROME_BIN=/usr/bin/google-chrome-stable
ENV CHROMEDRIVER=/usr/local/bin/chromedriver
# 设置定时任务
RUN echo "*/5 * * * * python /app/main.py >> /var/log/cron.log 2>&1" > /etc/cron.d/my-cron \
&& chmod 0644 /etc/cron.d/my-cron \
&& crontab /etc/cron.d/my-cron
# 创建日志文件
RUN touch /var/log/cron.log
# 启动 cron 服务并运行主服务
CMD ["sh", "-c", "cron && tail -f /var/log/cron.log"]