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.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github