Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "The input device is not a TTY"

I am running the following command from my Jenkinsfile. However, I get the error "The input device is not a TTY".

docker run -v $PWD:/foobar -it cloudfoundry/cflinuxfs2 /foobar/script.sh 

Is there a way to run the script from the Jenkinsfile without doing interactive mode?

I basically have a file called script.sh that I would like to run inside the Docker container.

like image 936
Anthony Avatar asked Mar 29 '17 16:03

Anthony


People also ask

What is TTY in Docker?

A pseudo terminal (also known as a tty or a pts ) connects a user's "terminal" with the stdin and stdout stream, commonly (but not necessarily) through a shell such as bash .

How do I run a command in a Docker container?

Running Commands in an Alternate Directory in a Docker Container. To run a command in a certain directory of your container, use the --workdir flag to specify the directory: docker exec --workdir /tmp container-name pwd.

What is Docker exec?

Docker exec is a command that allows the execution of any given command within a Docker container. This means it will interpret the arguments passed to it as commands to be run inside the container.

What does the flag do in a docker Run command?

The docker run command provides a flag that will copy the volumes from one or more containers to the new container. The flag --volumes-from can be set multiple times to specify multiple source containers.


2 Answers

Remove the -it from your cli to make it non interactive and remove the TTY. If you don't need either, e.g. running your command inside of a Jenkins or cron script, you should do this.

Or you can change it to -i if you have input piped into the docker command that doesn't come from a TTY. If you have something like xyz | docker ... or docker ... <input in your command line, do this.

Or you can change it to -t if you want TTY support but don't have it available on the input device. Do this for apps that check for a TTY to enable color formatting of the output in your logs, or for when you later attach to the container with a proper terminal.

Or if you need an interactive terminal and aren't running in a terminal on Linux or MacOS, use a different command line interface. PowerShell is reported to include this support on Windows.


What is a TTY? It's a terminal interface that supports escape sequences, moving the cursor around, etc, that comes from the old days of dumb terminals attached to mainframes. Today it is provided by the Linux command terminals and ssh interfaces. See the wikipedia article for more details.

To see the difference of running a container with and without a TTY, run a container without one: docker run --rm -i ubuntu bash. From inside that container, install vim with apt-get update; apt-get install vim. Note the lack of a prompt. When running vim against a file, try to move the cursor around within the file.

like image 52
BMitch Avatar answered Oct 29 '22 11:10

BMitch


For docker run DON'T USE -it flag

(as said BMitch)

And it's not exactly what you are asking, but would be also useful for others:

For docker-compose exec use -T flag!

The -T key would help people who are using docker-compose exec! (It disable pseudo-tty allocation)

For example:

docker-compose -f /srv/backend_bigdata/local.yml exec -T postgres backup 

or

docker-compose exec -T mysql mysql -uuser_name -ppassword database_name < dir/to/db_backup.sql 
like image 22
yestema Avatar answered Oct 29 '22 10:10

yestema