如何在CentOS Dockerfile中安装适配ChromeDriver 114的Google Chrome
解决CentOS7 Docker容器中安装指定版本Chrome 114以匹配ChromeDriver的问题
问题背景
当前基于CentOS7的Dockerfile默认安装最新稳定版Google Chrome,但该版本与已有的ChromeDriver 114不兼容,且无法获取适配最新Chrome 124的ChromeDriver版本,因此需要安装Chrome 114版本以实现版本匹配。
解决方案
需要修改Dockerfile中安装Google Chrome和安装ChromeDriver的两个代码块,具体调整如下:
1. 替换Chrome安装逻辑
将原有的下载最新Chrome RPM的代码,替换为下载指定114版本的RPM包并安装:
# INSTALL GOOGLE CHROME RUN yum -y update; yum clean all RUN yum -y install mesa-dri-drivers libexif libcanberra-gtk2 libcanberra; yum clean all # 下载Chrome 114指定版本RPM RUN curl -o /root/google-chrome-stable-114.0.5735.198-1.x86_64.rpm https://dl.google.com/linux/chrome/rpm/stable/x86_64/google-chrome-stable-114.0.5735.198-1.x86_64.rpm # 安装指定版本Chrome RUN yum -y install /root/google-chrome-stable-114.0.5735.198-1.x86_64.rpm; yum clean all RUN dbus-uuidgen > /etc/machine-id
2. 修正ChromeDriver下载链接
原Dockerfile中ChromeDriver版本变量设为114.0.5735.90,但下载的是122版本的包,需修正为对应114版本的下载链接:
# INSTALL CHROMEDRIVER RUN CHROMEDRIVER_VERSION="114.0.5735.90" && \ mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION && \ curl -sS -o /tmp/chromedriver_linux64.zip https://storage.googleapis.com/chrome-for-testing-public/${CHROMEDRIVER_VERSION}/linux64/chromedriver-linux64.zip && \ unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION && \ rm /tmp/chromedriver_linux64.zip && \ chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver-linux64 && \ ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver-linux64 /usr/local/bin/chromedriver
完整修改后的Dockerfile(关键部分已更新)
如果需要替换整个Dockerfile,以下是整合后的完整内容:
FROM centos:7 MAINTAINER The CentOS Project <cloud-ops@centos.org> LABEL Vendor="CentOS" \ License=GPLv2 \ Version=2.4.6-40 RUN yum -y install wget epel-release RUN yum -y --setopt=tsflags=nodocs update && \ yum -y --setopt=tsflags=nodocs install httpd && \ yum clean all RUN yum -y update && yum -y install git RUN yum -y install \ https://repo.ius.io/ius-release-el7.rpm \ https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm RUN yum install yum-utils RUN yum -y install httpd-devel --skip-broken\ zlib-devel \ bzip2-devel \ openssl-devel \ ncurses-devel \ sqlite-devel \ readline \ https://centos7.iuscommunity.org/ius-release.rpm \ python36u \ python36u-pip \ python36u-devel \ uwsgi \ uwsgi-plugin-python36u \ python-pip \ mysql-devel \ unzip RUN yum -y group install "Development Tools" RUN yum clean all; RUN yum -y install gcc RUN pip3.6 install --upgrade pip && pip3.6 install boto && pip3.6 install boto3 RUN yum -y install https://centos7.iuscommunity.org/ius-release.rpm python36u python36u-devel python36u-pip RUN pip3.6 install pathlib # INSTALL GOOGLE CHROME RUN yum -y update; yum clean all RUN yum -y install mesa-dri-drivers libexif libcanberra-gtk2 libcanberra; yum clean all # 下载Chrome 114指定版本RPM RUN curl -o /root/google-chrome-stable-114.0.5735.198-1.x86_64.rpm https://dl.google.com/linux/chrome/rpm/stable/x86_64/google-chrome-stable-114.0.5735.198-1.x86_64.rpm # 安装指定版本Chrome RUN yum -y install /root/google-chrome-stable-114.0.5735.198-1.x86_64.rpm; yum clean all RUN dbus-uuidgen > /etc/machine-id # INSTALL CHROMEDRIVER RUN CHROMEDRIVER_VERSION="114.0.5735.90" && \ mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION && \ curl -sS -o /tmp/chromedriver_linux64.zip https://storage.googleapis.com/chrome-for-testing-public/${CHROMEDRIVER_VERSION}/linux64/chromedriver-linux64.zip && \ unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION && \ rm /tmp/chromedriver_linux64.zip && \ chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver-linux64 && \ ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver-linux64 /usr/local/bin/chromedriver RUN /bin/pip3.6 install django==2.1 RUN /bin/pip3.6 install channels==2.2.0 RUN /bin/pip3.6 install djangorestframework==3.10.2 RUN /bin/pip3.6 install django-cors-headers==3.1.0 RUN /bin/pip3.6 install mysqlclient RUN /bin/pip3.6 install mysql-connector-python RUN /bin/pip3.6 install djangorestframework-jwt==1.11.0 RUN /bin/pip3.6 install Pillow channels_redis==2.4.0 pymysql RUN /bin/pip3.6 install boto3==1.11.0 RUN /bin/pip3.6 install django==2.1 RUN /bin/pip3.6 install python-decouple RUN /bin/pip3.6 install selenium==3.141.0 RUN /bin/pip3.6 install chromedriver-autoinstaller RUN mkdir -p /web/www/Django COPY Django/ /web/www/Django COPY start.sh /start.sh COPY settings.ini /web/www/Django/WhatsappAdmin/settings.ini COPY requirements.txt web/www/Django/WhatsappAdmin/requirements.txt RUN /bin/pip3.6 install -r /web/www/Django/WhatsappAdmin/requirements.txt RUN chmod +x /start.sh RUN yum install -y uwsgi-logger-file uwsgi-plugin-python36u --skip-broken RUN touch /etc/uwsgi.d/whatsapp.ini RUN echo "[uwsgi]" > /etc/uwsgi.d/whatsapp.ini RUN echo "socket = /run/whatsappuwsgi/uwsgi.sock" >> /etc/uwsgi.d/whatsapp.ini RUN echo "chmod-socket = 775" >> /etc/uwsgi.d/whatsapp.ini RUN echo "chdir = /web/www/Django/WhatsappAdmin" >> /etc/uwsgi.d/whatsapp.ini RUN echo "master = true" >> /etc/uwsgi.d/whatsapp.ini RUN echo "module = WhatsappAdmin.wsgi:application" >> /etc/uwsgi.d/whatsapp.ini RUN echo "uid = uwsgi" >> /etc/uwsgi.d/whatsapp.ini RUN echo "gid = uwsgi" >> /etc/uwsgi.d/whatsapp.ini RUN echo "processes = 1" >> /etc/uwsgi.d/whatsapp.ini RUN echo "threads = 1" >> /etc/uwsgi.d/whatsapp.ini RUN echo "plugins = python36u,logfile" >> /etc/uwsgi.d/whatsapp.ini RUN mkdir -p /run/whatsappuwsgi/ RUN chmod 2775 /run/whatsappuwsgi RUN touch /run/whatsappuwsgi/uwsgi.sock RUN chgrp -R 0 /web/www/Django/WhatsappAdmin/* /start.sh /run /run/whatsappuwsgi/* /var/lib /var/log /usr/sbin/uwsgi \ && chmod -R g=u /web/www/Django/WhatsappAdmin/* /start.sh /run /run/whatsappuwsgi/* /usr/sbin/uwsgi /var/lib /var/log EXPOSE 5000 CMD ["/start.sh"]
说明
- Chrome 114的RPM包选择了该版本的最后一个稳定构建(114.0.5735.198),确保安装后能与ChromeDriver 114.0.5735.90完全兼容。
- 修正ChromeDriver下载链接时使用了版本变量,后续若需调整版本只需修改
CHROMEDRIVER_VERSION的值即可。
内容的提问来源于stack exchange,提问作者ankur kumar
相关产品推荐
相关产品推荐

