1

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.

John
  • 181
  • 2
  • 12
  • What is the error you get? – Hans Kilian Mar 27 '22 at 08:14
  • When I run it (Ubuntu host), it works as it should. – Hans Kilian Mar 27 '22 at 08:21
  • I m running it on Windows machine and updated the error please check. – John Mar 27 '22 at 08:33
  • 1
    Nothing in the code you show should create a PNG file; what generated the image you attached? (Did you mean to include text-form logs instead?) How are you building and running the image (what are the exact `docker build` and `docker run` commands)? – David Maze Mar 27 '22 at 10:34
  • I used "docker build -t . " to build docker image and "docker run arg1 arg2" used this to run the image – John Mar 27 '22 at 19:46

1 Answers1

1

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"
John
  • 181
  • 2
  • 12