Trying to run my docker image using the below command:
docker run -v c:/users/dmsss/downloads/green2/test_data:/src/java/data/ solution/me_javasolu java green.java data/test1.csv data/result.csv
I’m getting the following error:
Exception in thread "main" Give paths to input and output files:
null
java.lang.NullPointerException
at green.main(green.java:39)
My green.main code snippet:
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Give paths to input and output files:");
String names=br.readLine();
System.out.println(names);
As you can see in the place of "names" i’m getting null, instead of "data/test1.csv data/result.csv".
I know that using: docker run -it, will give the desired outcome, but I want the inputs to be given in the same line as run
docker run -it solution/me_javasolu
Give paths to input and output files:
test_data/test3.csv test_data/result.csv
test_data/test3.csv test_data/result.csv
Profit: $99
Hope I get a solution to the problem, thanks in advance.
2
Answers
You have already mapped volumes to your docker container.
Try to use these paths inside your code instead of reading it from the console.
Paths.get("your path")
If you want to read from the console then you have to keep STDIN open which can be done by running your container in interactive mode.
The arguments at the end of your docker command are passed as arguments to your java main method.
If you want to provide input on STDIN to your java application inside your container you need to do something like this: