Dockerfile
FROM python:3.10-busterRUN (echo "deb http://mirrors.aliyun.com/debian/ buster main non-free contrib" > /etc/apt/sources.list)
RUN (apt-get update) && (apt-get upgrade)
RUN (apt-get install -ylsb-release wget ttf-wqy-zenhei xfonts-intl-chinese wqy*) WORKDIR /code
RUN mkdir /code/depends
# 下载并安装 chrome, TIPS: dpkg 不会处理依赖,要使用 apt 安装 deb
RUN (wget -P /code/depends https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb) && ( apt install -y /code/depends/google-chrome-stable_current_amd64.deb)COPY install.py /code/
RUN python install.pyRUN /usr/local/bin/python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
COPY requirements-prd.txt /code/
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements-prd.txt
COPY config.yaml /code/
COPY . /code/
让我们一行一行来看
RUN (echo "deb http://mirrors.aliyun.com/debian/ buster main non-free contrib" > /etc/apt/sources.list)
这行的作用是使用 aliyun 的 debian apt 仓库,原因当然是邪恶长城RUN (apt-get update) && (apt-get upgrade)
更新一下 apt 源,并更新软件。可以只要apt-get update
,而删除apt-get upgrade
,后者不是必须项RUN (apt-get install -y lsb-release wget ttf-wqy-zenhei xfonts-intl-chinese wqy*)
这几个包用来干嘛呢?安装中文字体,作用会在下面讲到
【docker 打包 selenium+chromedriver+chrome 解决方案】没有这么多麻烦的事情,你装个 Linux Desktop 难道不是自带中文的?还要你自己去网上下字体文件的?
很简单,apt 仓库里面都有准备好的字体,直接用 apt 命令一键安装就好了!
apt-get install -ylsb-release wget ttf-wqy-zenhei xfonts-intl-chinese wqy*