Is Docker writing to stdin? How can I stop it?

I have a simple Go app that I’m trying to wrap in Docker. If I run the Go app in a terminal window on my Mac, the Go app starts up and prints a welcome message to stdout. This app is a simple command line tool, I can type in some commands in the terminal and the app reads from stdin, and the prints some information to stdout so I can read it.

The app offers 9 options, and I pick from one of the 9 options to get different kinds of information. I type a number and hit enter and the app reads that from stdin.

However, if I type something else, other than the numbers 1 thourgh 9, then I get this message:

Invalid Option. Please choose again.

It’s a simple app so I thought I could use a simple Dockerfile:

FROM golang:1.22.4
WORKDIR /app
COPY go.mod ./
RUN go mod download
COPY *.go ./
RUN CGO_ENABLED=0 GOOS=linux go build -o /docker-gs-ping
CMD ["/docker-gs-ping"]

And then run it simply:

docker run --name rainbow docker-gs-ping

But when I do this and then look at the log, I see an endless stream of:

Invalid Option. Please choose again. 


Invalid Option. Please choose again. 


Invalid Option. Please choose again. 


Invalid Option. Please choose again.

It’s as if something is writing to the stdin.

On my Mac, in the terminal, if I simply held down the Enter key, I would see that same error repeat the same way.

But inside of Docker, what would be sending messages to stdin?

Again, at startup, the app prints a welcome message to stdout. Could that provoke a response from Docker?

How do I get control of the situation? I don’t want anything written to stdin, unless I use “docker exec” to write something.

Hmm, running interactive helps. If I do this:

docker run -i -d --name rainbow docker-gs-ping

I’ve added the “-i” flag.

Now if I look in the logs I see the correct output. Though interaction is still a question mark.

Run this command to create a container that drops you in the sh shell

docker run -it --rm --name rainbow --entrypoint sh docker-gs-ping

Then check if /docker-gs-ping actually behaves like it does on your mac.