如何在Dockerfile中使用Chrome for Testing搭建Selenium环境
在Docker容器中安装特定版本Chrome与Chromedriver的问题
背景与需求
需要在Docker容器中安装特定版本的Chrome和Chromedriver,避免二者版本不兼容,优先选择将二者存入本地代码库后导入容器安装。
当前尝试的Dockerfile及报错
使用eclipse-temurin:11镜像,Dockerfile内容如下:
FROM eclipse-temurin:11 WORKDIR /app/ COPY bin/drivers/chromedriver /tmp/ COPY bin/drivers/google-chrome-stable_current_amd64.deb /tmp/ RUN apt-get install -y wget RUN apt-get install -y /tmp/google-chrome-stable_current_amd64.deb #RUN dpkg -i /tmp/google-chrome-stable_current_amd64.deb #RUN apt -f install RUN chmod 755 /tmp/chromedriver && \ ln -fs /tmp/chromedriver /usr/bin/chromedriver RUN ls -la /usr/bin/chromedriver RUN ls -la /usr/bin/
该.deb包对应Chrome 90版本,安装时出现大量依赖错误:
#10 0.674 Some packages could not be installed. This may mean that you have #10 0.674 requested an impossible situation or if you are using the unstable #10 0.674 distribution that some required packages have not yet been created #10 0.674 or been moved out of Incoming. #10 0.674 The following information may help to resolve the situation: #10 0.674 #10 0.674 The following packages have unmet dependencies: #10 0.677 google-chrome-stable : Depends: fonts-liberation but it is not installable #10 0.677 Depends: libasound2 (>= 1.0.16) but it is not installable #10 0.679 E: Unable to correct problems, you have held broken packages. #10 0.681 Depends: libatk-bridge2.0-0 (>= 2.5.3) but it is not installable #10 0.681 Depends: libatk1.0-0 (>= 2.2.0) but it is not installable #10 0.681 Depends: libatspi2.0-0 (>= 2.9.90) but it is not installable
Chrome for Testing使用疑问
计划使用Chrome for Testing的120版本Chrome和Chromedriver,但下载的是完整文件夹结构而非.deb包,需解答:
- 在Docker中如何使用该文件夹结构?是否只需放到指定路径?具体路径是什么?
- 是否需要处理依赖问题?
Chromedriver配置正确性验证
以下Chromedriver的配置方式是否正确?
WORKDIR /app COPY bin/drivers/chromedriver /tmp/ RUN chmod 755 /tmp/chromedriver && \ ln -fs /tmp/chromedriver /usr/bin/chromedriver
镜像体积优化需求
当前镜像体积过大,希望替换为Alpine Linux镜像amazoncorretto:11-alpine3.18,请提供可行方案。
内容的提问来源于stack exchange,提问作者Vikas Palakkat
相关产品推荐
相关产品推荐

