Solved: The Input Device Is Not a TTY
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?
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
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.
-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.
How To Deal With Persistent Storage (e.g. Databases) In Docker?
The best way to deal with persistent data storage (such as a database) in Docker is to use Docker’s volume API (for docker 1.9.0 or newer) or use data-only containers for older versions of Docker. ...Questions
How to Remove a Docker Image?
To remove one or more specific images, you can use the docker rmi command. How to list all images If you want to list all the images before removing any, you can do they by running the following co...Questions
What Is the Difference between CMD and ENTRYPOINT in a Dockerfile?
There is a big confusion around similarity and lack of clarity in the difference between the CMD and ENTRYPOINT instruction in Docker. Let’s clear things up. See the example Let’s say we want to cr...Questions
How to Mount a Host Directory in a Docker Container?
If you want to mound a host directory in a Docker container, you have to main ways to do that: Using the ADD command: The simplest way is to use the dockers ADD command as shown below: ADD . /path/...Questions
We are hiring.
Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.
Help us in making the internet more reliable.
Help us with developer education and get paid.