chromedriver可运行的docker环境
以常见的linux x86服务器为例
chrome driver
官网:https://googlechromelabs.github.io/chrome-for-testing/
下载chrome linux64位:https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.85/xxx
下载chrome driver linux64位:https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.85/xxx
运行容器
docker run -itd \--name tophub \-v /root/miniconda3:/root/miniconda3 \-v /home/service/tophub:/app \-w /app \--network host \centos:8 /bin/bash
进入容器
docker exec -it tophub /bin/bash
在容器内设置环境变量
export PATH="/root/miniconda3/envs/tophub/bin:$PATH"
export CONDA_PREFIX="/root/miniconda3/envs/tophub"
首先备份原有的源
cd /etc/yum.repos.d/
mkdir backup
mv *.repo backup/
创建新的源文件
cat > /etc/yum.repos.d/CentOS-Base.repo << 'EOF'
[BaseOS]
name=CentOS-$releasever - Base
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
gpgcheck=0
enabled=1[AppStream]
name=CentOS-$releasever - AppStream
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/AppStream/$basearch/os/
gpgcheck=0
enabled=1[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/extras/$basearch/os/
gpgcheck=0
enabled=1[PowerTools]
name=CentOS-$releasever - PowerTools
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/PowerTools/$basearch/os/
gpgcheck=0
enabled=1
EOF
清理缓存并更新
dnf clean all
dnf makecache
现在可以安装软件包了
dnf install -y dnf-plugins-core
尝试不同的 PowerTools 仓库名称
dnf config-manager --set-enabled PowerTools || \
dnf config-manager --set-enabled power-tools || \
dnf config-manager --set-enabled centos-power-tools
安装需要的包
dnf install -y \nss \nss-tools \libX11 \libXcomposite \libXcursor \libXdamage \libXext \libXi \libXtst \cups-libs \libXrandr \libXScrnSaver \libXvMC \mesa-libgbm \alsa-lib \pango \atk \at-spi2-atk \gtk3
如果遇到找不到包的情况,我们可以启用 EPEL 仓库
dnf install -y epel-release
然后再次尝试安装
dnf install -y \nss \nss-tools \libX11 \libXcomposite \libXcursor \libXdamage \libXext \libXi \libXtst \cups-libs \libXrandr \libXss \libXvMC \mesa-libgbm \alsa-lib \pango \atk \at-spi2-atk \gtk3
验证chrome驱动
./chromedriver-linux64/chromedriver --version
# 正确回显如下
ChromeDriver 131.0.6778.87 (ce31cae9487357cfd3bd62984ed5250121a71a23-refs/branch-heads/6778@{#2287})