Search code examples
javadockerjardocker-volumewebdrivermanager-java

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


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?


Solution

  • 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.