我有一个应用程序,可以处理HTTP请求,并基于参数运行一些基本的硒操作(例如,打开网页)。 它是用Scala编写的,实际上实际上与Java实现非常接近。 代码示例如下所示:

val firefoxBinary = new FirefoxBinary() firefoxBinary.addCommandLineOptions("--headless")  val firefoxOptions = new FirefoxOptions() firefoxOptions.setBinary(firefoxBinary)  val webDriver = new FirefoxDriver(firefoxOptions) webDriver.get(s"https://google.com") webDriver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS) logger.info(s"Title: ${webDriver.getTitle}") webDriver.close() 

当我在本地运行时,一切正常。 但是当我将其打包在docker容器中时,出现以下错误:

Error servicing request: GET /run-selenium from 172.17.0.1 {{ org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:9340 Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: '4fb27eff9adc', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.184-linuxkit', java.version: '1.8.0_212' Driver info: driver.version: FirefoxDriver }} org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:9340 Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: '4fb27eff9adc', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.184-linuxkit', java.version: '1.8.0_212' Driver info: driver.version: FirefoxDriver     at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92) 

我使用此docker映像作为基础映像:

FROM openjdk:8-jre-alpine3.9 ARG firefox_ver=70.0 ARG geckodriver_ver=0.26.0  # Download and install deps RUN apk update && apk add curl curl-dev  RUN mkdir /opt/docker && chmod a=rwX /opt/docker  # Download and install Firefox RUN curl -fL -o /tmp/firefox.tar.bz2 https://ftp.mozilla.org/pub/firefox/releases/${firefox_ver}/linux-x86_64/en-GB/firefox-${firefox_ver}.tar.bz2 \ && tar -xjf /tmp/firefox.tar.bz2 -C /tmp/ && mv /tmp/firefox /opt/docker  # Download and install geckodriver RUN curl -fL -o /tmp/geckodriver.tar.gz \ https://github.com/mozilla/geckodriver/releases/download/v${geckodriver_ver}/geckodriver-v${geckodriver_ver}-linux64.tar.gz \ && tar -xzf /tmp/geckodriver.tar.gz -C /tmp/ && chmod +x /tmp/geckodriver && mv /tmp/geckodriver /opt/docker  ENV PATH="/opt/docker/firefox:${PATH}" 

未解决问题?本站智能推荐: