I'm using the Docker Java client in a Scala project to programmatically create images and start containers with volume(s), then when this is all done also execute a Java class within a jar file that is available in one of the attached volumes.
// Constructing the container and getting it's ID
val containerID = dockerClient
.createContainerCmd(imageID)
.withName(s"${namePrefix}_${RandomStringUtils.randomAlphanumeric(12)}")
.withTty(true)
.withVolumes(volume)
.withBinds(new Bind("/home/core/docker-dependencies", new Volume("/opt/dependencies")))
.exec()
.getId
// Starting the container
dockerClient
.startContainerCmd(containerID)
.exec()
The command I'm trying to run:
val command = s"""bash -c "java -cp /opt/dependencies/Platforms-assembly-0.2.4.jar com.org.test.platforms.common.Endpoint param1 param2}""""
The jar file referenced in the command is available in the volume that was bound at container creation.
I tried running different versions of the command, for example as simple Java command (without bash -c
), I also tried different location like the file's location on my local PC or the path on the machine where Docker is running, with the same result sadly.
// Preparing the command for execution
val executionID = dockerClient
.execCreateCmd(containerID)
.withCmd(command)
.exec()
.getId
// Starting the execution
dockerClient
.execStartCmd(executionID)
.withTty(true)
.exec(new ExecStartResultCallback(System.out, System.err))
.awaitCompletion()
The error I'm getting:
com.github.dockerjava.api.exception.NotFoundException: {"message":"rpc error: code = 2 desc = oci runtime error: exec failed: exec: \"bash -c \\\"java -cp /opt/dependencies/Platforms-assembly-0.2.4.jar com.org.test.platforms.common.Endpoint param1 param2\\\"\": stat bash -c \"java -cp /opt/dependencies/Platforms-assembly-0.2.4.jar com.org.test.platforms.common.Endpoint param1 param2\": no such file or directory"}
If I copy the aforementioned command, attach to the running container and run it, then it executes perfectly, which is the main reason why I'm lost on this issue. It is my understanding that the volume should be available at the time of the initial execution, it's certainly available when I attach to the container.