javadockerdockerfiledocker-imagedocker-run

Printing command line args (java program) when using docker run


I have a java program which prints command line arguments

 public class Sample {

    public static void main(String[] args) {
        System.out.println(args[0]);
        System.out.println(args[1]);
     }
   }

And I have a Docker file as below

FROM openjdk:8  
COPY . /src/java
WORKDIR /src/java  
RUN ["javac", "Sample.java"]  
ENTRYPOINT ["java", "Sample"]

I have built a docker image for the above program and used below command to run the docker image

docker run <image-name> hello world

When I run above command expected output is

Hello
world

but I'm getting an error as below. enter image description here Please, let me know my mistake. I'm new to docker.

Thanks in advance.


Solution

  • Build command to be used is

    docker build -t my-app:1.0 .
    

    Docker run command with args is

    docker run my-app:1.0 "Hello" "World"