Docker Java Application failing at obtaining input from console

I am trying to create a docker image for my java application. At startup this application needs to be given a password (currently via console).

I tried several methods of obtaining input however they have all failed. Is this a limitation of docker and if so is there a workaround?

  • How to pass parameters to a .net core project with dockerfile
  • Unknown filesystem type on /dev/mapper/docker-202
  • Certificate error while running boot2Docker
  • Is it possible to isolate docker container in user-defined overlay network from outside internet?
  • Fluentd capture stack traces from Docker
  • How to make docker-compose scale start dependencies?
  • For this snippet:

    Console console = System.console();
    if(console == null){
        System.out.println("console is null!!");
    } else {
        System.out.println("Input password: ");
        char[] password = console.readPassword("Pass: ");

    System.console() is returning null.

    For this snippet:

        System.out.println("Creating InputStreamReader");
        InputStreamReader s = new InputStreamReader(;
        System.out.println("Creating BufferedReader");
        BufferedReader r = new BufferedReader(s);
        System.out.println("Input password: ");
        String password = r.readLine();
        System.out.println("Password: "+password);

    the input is automatically skipped, (resulting in the String password to be null) with the program continuing execution as if there was no input requested. (password is null)

    For this snippet:

    Scanner s = new Scanner(;
    System.out.println("Input password: ");
    String password =;

    I get

    Exception in thread "main" java.util.NoSuchElementException
        at java.util.Scanner.throwFor(
        at com.docker.test.DockerTest.testScanner(

    I am running the program from within my image using docker run test/plaintest1

    my dockerfile is as follows

    FROM centos
    RUN yum install -y java-1.7.0-openjdk
    ADD DockerTest.jar /opt/ssm
    ENTRYPOINT ["java","-jar","/opt/ssm/DockerTest.jar"]
    CMD [""]

  • process.env.VARIABLE is undefined in webpack/docker/heroku deployment
  • Cannot launch interactive session in Windows IIS Docker container
  • How to check if the docker image has all the files?
  • docker not unzipping my files
  • How do I provide credentials to the docker awslogs driver using Docker for Mac?
  • How to add jdbc driver to weblogic server running on docker container?
  • 2 Solutions collect form web for “Docker Java Application failing at obtaining input from console”

    Solved it.

    By running the command using the -i and -t parameters you can be allowed to enter the password. using all 3 methods.

    so basically docker run -i -t <imagename> <params>

    I was struggling with this yesterday for most of the day. The problem seemed to have been a broken base image supplied by the official CentOS repo. If you look on your base image you will notice that /opt/java exists on the base image. That’s the clue that you have the broken image. Simply pull the latest image with “docker pull centos” and you’ll be back in action. They must have fixed it sometime last night. You’ll notice the hash of the image has changed even though it shows that the image was uploaded 2 weeks ago. Someone is trying to hide their tracks! Haha. Your Dockerfile is fine.


    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.