Docker部署SpringBoot Selenium爬虫报错:无法启动新会话求助
Selenium在Docker中启动ChromeDriver超时问题排查
环境信息
- 本地Chrome浏览器版本:119.0.6045.160
- ChromeDriver版本:119.0.6045.105
- Selenium Java版本:4.8.3
- 本地运行环境:SpringBoot,程序运行无报错
本地运行代码
ChromeOptions options = new ChromeOptions(); options.setBinary("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"); WebDriver driver = new ChromeDriver(options);
Docker运行报错信息
Exception in thread "main" java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) at org.springframework.boot.loader.Launcher.launch(Launcher.java:95) at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) Caused by: org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Host info: host: 'dd7e0e343e76', ip: '172.17.0.2' at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:561) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:229) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157) at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:101) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:88) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:84) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:73) at com.linggd.demo.Duldung2.myrun(Duldung2.java:64) at com.linggd.demo.Htmltest3Application.main(Htmltest3Application.java:85) ... 8 more Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver process to start. Build info: version: '4.8.3', revision: 'e5e76298c3' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.16.3-microsoft-standard-WSL2', java.version: '17.0.9' Driver info: driver.version: ChromeDriver at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:208) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:114) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543) ... 16 more
当前使用的Dockerfile
FROM debian:bullseye-slim WORKDIR /app EXPOSE 8081 # Install required dependencies RUN apt-get update && apt-get install -y openjdk-17-jre-headless libnss3 libxcb1 RUN apt-get install -y wget libgdk-pixbuf2.0-0 libnss3 libatk-bridge2.0-0 libcups2 libdrm2 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libxkbcommon-x11-0 libpangocairo-1.0-0 libasound2 ENV CHROME_VERSION "119.0.6045.159-1" RUN set -ex && \ apt-get update -qqy && \ wget --no-check-certificate https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb && \ apt-get install -qqyf ./google-chrome-stable_${CHROME_VERSION}_amd64.deb && \ rm google-chrome-stable_${CHROME_VERSION}_amd64.deb COPY target/springboot-aws-exe.jar /app/ COPY chromedriver.exe /app/chromedriver ENTRYPOINT ["java", "-jar", "/app/springboot-aws-exe.jar"]
疑问
本地SpringBoot程序运行正常,但Docker镜像启动时出现ChromeDriver启动超时错误。已尝试在Docker中安装指定版本的Chrome(119.0.6045.159-1),但问题仍未解决。请问哪里操作出错了?
内容的提问来源于stack exchange,提问作者user16187251
相关产品推荐
相关产品推荐

