0

So my program has a condition like

While(not 'e'){ 
  ask the user to input a string
  }

So when I build an image for my program and try to run it via docker run I run into an infinite loop without even getting a chance to enter in my input.

I am fairly new to docker, please can you tell me why that might be happening.

Markus W Mahlberg
  • 19,711
  • 6
  • 65
  • 89
Shivangi Singh
  • 1,001
  • 2
  • 11
  • 20
  • How does your `docker run` command look like? It's most likely you run the command "non interactively", so if you don't specify it docker will not attach STDIN (that's the file-handle for reading user input) even if your container runs in foreground. To attach stdin you can use the `-i` flag as described in the [`docker run` documentation](https://docs.docker.com/engine/reference/run/#foreground). I always run my containers like this `docker run -ti --rm your-image-name` (`--rm` removes the container after exit and `-t` allocates a pseudo tty for a more shell-like feature-set). – vstm Jul 29 '18 at 18:53
  • Welcome to Stack Overflow! It's helpful to include your actual code when asking a question; your Dockerfile, the `docker run` command involved, and a minimal subset of the Go code would all be useful to understand what's going on. The SO documentation has some tips on writing a [mcve]. – David Maze Jul 29 '18 at 19:33

1 Answers1

0

To run a program that takes input from the terminal use

'docker run -I <ImageName> 
Shivangi Singh
  • 1,001
  • 2
  • 11
  • 20