Search code examples
javamavendockerfabric8docker-maven-plugin

Can't read user input inside the Docker using Maven plugin


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

Solution

  • 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.