Solved: The Input Device Is Not a TTY

Better Stack Team
Updated on August 1, 2022

If you try to execute a command inside the docker using the Jenkins or jus try to use the -it option in the docker run command, you will get the following error:

the input device is not a TTY

How to fix the error?

The fix is pretty simple, all you need to do is to remove the -it options from the docker run command. If you want to know why is that, you can continue reading the following section.

Why do a get this error?

The docker run/exec -i command will connect the STDIN (Standard input) of the command inside the container to the STDIN of the docker run/exec itself.

Try running something like this: docker run -i ubuntu cat

You will notice that the container will not exit until you send CTRL+D because the main process cat is for input from the infinite stream that is the terminal input of the docker run

If you try something like this: echo "hello" | docker run -i ubuntu cat (notice the pipe operator). It will print hello and exit right after because docker noticed that the cat command terminated, thus docker terminated the container.

If you change the -i option to -t option, the command will look like this: docker run -t ubuntu cat. It will give you an empty line, because while the cat is connected to the input, the input is not connected your input (as mentioned before). If you get your shell back by pressing CTRL + C, and then list all running containers, you will notice that the container is still running, because the cat is still waiting for input.

Now, for -it together. This tells cat that its input is a terminal and in the same time connect this terminal to the input of docker run which is a terminal. docker run/exec will make sure that its own input is in fact a tty before passing it to cat. This is why you will get a input device is not a TTY if you try echo "hello" | docker run -it alpine cat because in this case, the input of docker run itself is the pipe from the previous echo and not the terminal where docker run is executed.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack