Error “The input device is not a TTY”

后端 未结 11 1148
野的像风
野的像风 2020-11-27 09:20

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:         


        
相关标签:
11条回答
  • 2020-11-27 09:39

    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 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 color output, 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.

    0 讨论(0)
  • 2020-11-27 09:40

    If you are (like me) using git bash on windows, you just need to put

    winpty

    before your 'docker line' :

    winpty docker exec -it some_cassandra bash
    
    0 讨论(0)
  • 2020-11-27 09:41

    My Jenkins pipeline step shown below failed with the same error.

           steps {
                echo 'Building ...' 
                sh 'sh ./Tools/build.sh'
            }
    

    In my "build.sh" script file "docker run" command output this error when it was executed by Jenkins job. However it was working OK when the script ran in the shell terminal.The error happened because of -t option passed to docker run command that as I know tries to allocate terminal and fails if there is no terminal to allocate.

    In my case I have changed the script to pass -t option only if a terminal could be detected. Here is the code after changes :

    DOCKER_RUN_OPTIONS="-i --rm"
    
    # Only allocate tty if we detect one
    if [ -t 0 ] && [ -t 1 ]; then
        DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -t"
    fi
    
    docker run $DOCKER_RUN_OPTIONS --name my-container-name  my-image-tag
    
    0 讨论(0)
  • 2020-11-27 09:42

    Using docker-compose exec -T fixed the problem for me via Jenkins

    docker-compose exec -T containerName php script.php

    0 讨论(0)
  • 2020-11-27 09:43

    when using 'git bash',

    1) I execute the command:

    docker exec -it 726fe4999627 /bin/bash
    

    I have the error:

    the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'
    

    2) then, I execute the command:

    winpty docker exec -it 726fe4999627 /bin/bash
    

    I have another error:

    OCI runtime exec failed: exec failed: container_linux.go:344: starting container process caused "exec: \"D:/Git/usr/bin/
    bash.exe\": stat D:/Git/usr/bin/bash.exe: no such file or directory": unknown
    

    3) third, I execute the:

    winpty docker exec -it 726fe4999627 bash
    

    it worked.

    when I using 'powershell', all worked well.

    0 讨论(0)
  • 2020-11-27 09:43

    I know this is not directly answering the question at hand but for anyone that comes upon this question who is using WSL running Docker for windows and cmder or conemu.

    The trick is not to use Docker which is installed on windows at /mnt/c/Program Files/Docker/Docker/resources/bin/docker.exe but rather to install the ubuntu/linux Docker. It's worth pointing out that you can't run Docker itself from within WSL but you can connect to Docker for windows from the linux Docker client.

    Install Docker on Linux

    sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    sudo apt-get update
    sudo apt-get install docker-ce
    

    Connect to Docker for windows on the port 2375 which needs to be enabled from the settings in docker for windows.

    docker -H localhost:2375 run -it -v /mnt/c/code:/var/app -w "/var/app" centos:7

    Or set the docker_host variable which will allow you to omit the -H switch

    export DOCKER_HOST=tcp://localhost:2375

    You should now be able to connect interactively with a tty terminal session.

    0 讨论(0)
提交回复
热议问题