I hava Java project and I want to execute docker command from my code. Command:
docker run --rm -v "$(pwd)":/browsertime sitespeedio/browsertime:16.3.0 --video --visualMetrics https://www.sitespeed.io/
I have tried to write Java class with following code inside main-method:
Runtime.getRuntime().exec("docker run --rm -v \"$(pwd)\":/browsertime sitespeedio/browsertime:16.3.0 --video --visualMetrics https://www.sitespeed.io/");
This has compiled fine and got the result in console "Process finished with exit code 0", so everything has been okey, but no result had been got (that command had to create folders and files and so on...).
So how should I run that docker command? If you have answer using DockerClient (not directly using Runtime.getRuntime().exec) - then go here: How can I execute predefined docker command from Java application with DockerClient?
$(pwd)work. There is no magic that fills up that$(pwd)when you send a command string within java. YOUR code has to make sure that the correct path information is already in that string that you "send down" to be executed!dockershell command. But do remember that the ability to launch a Docker container at all comes with the power to root the entire host, and that this approach won't necessarily be portable to other container runtimes.$(pwd)is command substitution; variable expansion is${PWD}or$PWD(and it can be either a shell variable or an environmental variable). But the main point is correct that both of these (and more) work only in shell not java.