在Docker中装载卷时出现无法访问jarfile错误



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

当我按如下方式运行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

有人知道如何映射我想要的体积并避免这个错误吗?

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

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

最新更新