1

Description

I'm writing a simple console application that starts in a Docker container, reads user input and processes it. For automating Docker I use docker-maven-plugin. The code for reading user input is the following:

new Scanner(System.in).nextLine()

Tried also the following:

new BufferedReader(new InputStreamReader(System.in)).readLine()

Running an application without Docker works in both cases.

I run the docker with command: mvn clean docker:build docker:run

However in Docker when it comes to user input the code simply returns null and doesn't block for user input. In case of Scanner I get java.util.NoSuchElementException: No line found which is basically the same.

I've found a similar issue on StackOverflow where passing the command line parameters -i -tseem to help.

Is there any way I could add these command line parameters to Maven run configuration? Or any ideas why this issue happens?

Info

  • Maven version : 3.3.9
  • Docker version : 1.13.1
Community
  • 1
  • 1
yyunikov
  • 5,719
  • 2
  • 43
  • 78
  • You realize docker containers run in a virtual machine which is separate from ur PC right? U need to ssh to the container then use ur java app from there. Which brings the question, why do u need to run ur app with docker? – Ean V Feb 14 '17 at 12:00
  • @EanV Yes, sure I understand. The Java app is starting automatically by Maven plugin using `` option after container startup, but the question is about execution of the Java app from docker container and why system input is not blocking. – yyunikov Feb 14 '17 at 12:04

1 Answers1

2

It is not possible with docker-maven-plugin. See this.

I also agree with rhuss (last comment in the link) as well. You are using maven which is a build tool and then starting containers which will probably help you in some way to build-test something. Also, if you refer to this section in docker documentation, it says

Specifying -t is forbidden when the client standard output is redirected or piped

which probably a build plugin will do.

GauravJ
  • 2,162
  • 1
  • 22
  • 28
  • Thanks for the answer. The solution which worked for me is building an image with `mvn docker:build` and then connecting to it using `docker run -i -t [image-name]` – yyunikov Feb 15 '17 at 10:25