Unable to access jarfile error when mounting a volume in a Docker

huangapple go评论87阅读模式
英文:

Unable to access jarfile error when mounting a volume in a Docker

问题

我有一个运行Java应用程序的Docker容器,该应用程序打包成一个fat-jar(即包含所有依赖项)。 Dockerfile 在 GitHub 上是公开的,容器在 Docker Hub 上也是公开的。请注意,我在Dockerfile中使用了 CMD 而不是 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

有人知道如何映射我想要的卷并避免此错误吗?

英文:

I have a Docker container that executes a Java application packaged as a fat-jar (i.e., shipped with all dependencies). The Dockerfile is public in GitHub, and the container is public in Docker Hub. Notice that I am using CMD in the Dockerfile instead of ENTRYPOINT since I need to pass an argument (called BROWSER) to java -jar.

When I run the Docker container as follows, everything goes fine:

$ 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

The problem happens when I map a volume as follows:

$ 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

Does anybody know how to map the volume I want and avoid this error?

答案1

得分: 1

When the image is built, the webdrivermanager-${VERSION}-fat.jar is copied into the /wdm directory inside the docker container. Then, when you start the container with -v ${PWD}:/wdm, the /wdm directory is masked by the ${PWD}, so the JAR file is not there.

I'm guessing that what you want to achieve is making the driver downloaded by the container accessible from the host machine. A possible solution would be downloading it to a different directory than the one where the JAR is placed, and mounting this download directory.

英文:

When the image is build, the webdrivermanager-${VERSION}-fat.jar is copied into the /wdm directory inside the docker container. Then, when you start the container with -v ${PWD}:/wdm, the /wdm directory is masked by the ${PWD}, so the JAR file is not there.

I'm guessing, that what you want to achieve is making the driver downloaded by the container accessible from the host machine. A possible solution would be downloading it to a different directory than the one where the JAR is placed, and mounting this download directory.

huangapple
  • 本文由 发表于 2020年8月11日 22:05:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63359876.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定