Francesco Borzi
Francesco Borzi

Reputation: 61954

Docker container with console app inserts commands inifitely

I have a Dockerfile that builds an image containing a custom console application:

FROM ubuntu:bionic

# Some non-relevant steps...

CMD  bin/my-console-app

my-console-app is a simple console app that, while it runs, it normally gives you the possibility of inserting commands.

For example

./my-console-app
my-console> some-command
Some result
my-console> some-other-command
Some other result

if I run the container that I've build using the above Dockerfile using -d, everything is fine:

docker run --name my-app --network host -d myapp

using the network I can see that the console app is correctly running.

However if I run it without -d, like:

docker run --name my-app --network host myapp

then my terminal will go crazy, like someone is constantly pressing ENTER:

my-console> 
my-console> 
my-console> 
my-console> 
my-console> 
my-console> 
my-console> 
my-console>
...

and this goes on forever. I cannot insert any command to my console app.

Why is that happening? What should I do to prevent this?

Upvotes: 0

Views: 78

Answers (1)

Francesco Borzi
Francesco Borzi

Reputation: 61954

I solved my issue by passing -it to the docker run command.

So now I run my container using:

docker run --name my-app --network host -it myapp

EDIT: if using docker-compose, to solve this problem specify those 2 options for the service:

stdin_open: true
tty: true

thanks @user268396

Upvotes: 1

Related Questions