0

我有一个 Docker 容器,它执行打包为fat-jar的 Java 应用程序(即,附带所有依赖项)。Dockerfile 在GitHub中是公开的,容器在Docker Hub中是公开的。请注意,我 CMD在 Dockerfile 中使用,而不是ENTRYPOINT因为我需要将参数(称为BROWSER)传递给java -jar.

当我按如下方式运行 Docker 容器时,一切正常:

$ docker run --rm -e BROWSER=chrome bonigarcia/webdrivermanager:4.1.0
[INFO] Using WebDriverManager to resolve chrome
[DEBUG] Created new resolution cache file at /root/.m2/repository/webdriver/resolution.properties
[DEBUG] Running command on the shell: [google-chrome, --version]
[DEBUG] There was a problem executing command <google-chrome --version> on the shell: Cannot run program "google-chrome" (in directory "."): error=2, No such file or directory
[DEBUG] Result: 
[DEBUG] The driver version for Chrome is unknown ... trying with latest
[DEBUG] Latest version of chromedriver according to https://chromedriver.storage.googleapis.com/LATEST_RELEASE is 84.0.4147.30
[INFO] Reading https://chromedriver.storage.googleapis.com/ to seek chromedriver
[DEBUG] Driver to be downloaded chromedriver 84.0.4147.30
[INFO] Downloading https://chromedriver.storage.googleapis.com/84.0.4147.30/chromedriver_linux64.zip
[INFO] Extracting binary from compressed file chromedriver_linux64.zip
[INFO] Driver location: /wdm/chromedriver

当我按如下方式映射卷时会出现问题:

$ docker run --rm -e BROWSER=chrome -v ${PWD}:/wdm bonigarcia/webdrivermanager:4.1.0
Error: Unable to access jarfile webdrivermanager-4.1.0-fat.jar

有谁知道如何映射我想要的音量并避免这个错误?

4

1 回答 1

1

构建映像时,会将其webdrivermanager-${VERSION}-fat.jar复制到/wdmdocker 容器内的目录中。然后,当您使用 启动容器时-v ${PWD}:/wdm/wdm目录被 屏蔽${PWD},因此 JAR 文件不存在。

我猜,您想要实现的是使容器下载的驱动程序可以从主机访问。一种可能的解决方案是将其下载到与放置 JAR 的目录不同的目录,然后挂载此下载目录。

于 2020-08-11T14:43:54.987 回答