docker exec -it returns "cannot enable tty mode on non tty input"

CentosDocker

Centos Problem Overview


docker exec -it command returns following error "cannot enable tty mode on non tty input"

level="fatal" msg="cannot enable tty mode on non tty input" 

I am running docker(1.4.1) on centos box 6.6. I am trying to execute the following command docker exec -it containerName /bin/bash but I am getting following error

level="fatal" msg="cannot enable tty mode on non tty input" 

Centos Solutions


Solution 1 - Centos

Running docker exec -i instead of docker exec -it fixed my issue. Indeed, my script was launched by CRONTAB which isn't a terminal.

As a reminder:

Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

Run a command in a running container

  -i, --interactive=false    Keep STDIN open even if not attached  
  -t, --tty=false            Allocate a pseudo-TTY

Solution 2 - Centos

If you're getting this error in windows docker client then you may need to use the run command as below

$ winpty docker run -it ubuntu /bin/bash

Solution 3 - Centos

just use "-i"

> docker exec -i [your-ps] [command]

Solution 4 - Centos

If you're on Windows and using docker-machine and you're using GIT Bash or Cygwin, to "get inside" a running container you'll need to do the following:

docker-machine ssh default to ssh into the virtual machine (Virtualbox most likely)

docker exec -it <container> bash to get into the container.

EDIT:

I've recently discovered that if you use Windows PowerShell you can docker exec directly into the container, with Cygwin or Git Bash you can use winpty docker exec -it <container> bash and skip the docker-machine ssh step above.

Solution 5 - Centos

I get "cannot enable tty mode on non tty input" for the following command on windows with boot2docker

docker exec -it <containerIdOrName> bash

Below command fixed the problem

winpty docker exec -it <containerIdOrName> bash

Solution 6 - Centos

docker exec runs a new command in an already-running container. It is not the way to start a new container -- use docker run for that.

That may be the cause for the "non tty input" error. Or it could be where you are running docker. Is it a true terminal? That is, is a full tty session available? You might want to check if you are in an interactive session with

[[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'

from https://unix.stackexchange.com/questions/26676/how-to-check-if-a-shell-is-login-interactive-batch

Solution 7 - Centos

I encountered this same error message in Windows 7 64bit using Mintty shipped with Git for Windows. $docker run -i -t ubuntu /bin/bash cannot enable tty mode on non tty input

I tried to prefix the above command with winpty as other answers suggested but running it showed me another error message below: $ winpty docker run -i -t ubuntu /bin/bash exec: "D:\\Git\\usr\\bin\\bash": executable file not found in $PATH docker: Error response from daemon: Container command not found or does not exist..

Then I happened to run the following command which gave me what I want: $ winpty docker run -i -t ubuntu bash root@512997713d49:/# ls bin dev home lib64 mnt proc run srv tmp var boot etc lib media opt root sbin sys usr root@512997713d49:/#

Solution 8 - Centos

I'm running docker exec -it under jenkins jobs and getting error 'cannot enable tty mode on non tty input'. No output to docker exec command is returned. My job login sequence was:

jenkins shell -> ssh user@<testdriver> -> ssh root@<sut> -> su - <user> -> docker exec -it <container>

I made a change to use -T flag in the initial ssh from jenkins. "-T - Disable pseudo-terminal allocation". And use -i flag with docker exec instead of -it. "-i - interactive. -t - allocate pseudo tty.". This seems to have solved my problem.

jenkins shell -> ssh -T user@<testdriver> -> ssh root@<sut> -> su - <user> -> docker exec -i <container>

Behaviour kindof matches this docker exec tty bug: https://github.com/docker/docker/issues/8755. Workaround on that docker bug discussion suggests using this:

docker exec -it <CONTAINER> script -qc <COMMAND>

Using that workaround didn't solve my problem. It is interesting though. Try these using different flags and under different ssh invocations, you can see 'not a tty' even with using -t with docker exec:

$ docker exec -it <CONTAINER> script -qc 'tty'
/dev/pts/0
$ docker exec -it <CONTAINER> 'tty'            
not a tty
$ docker exec -it <CONTAINER> bash -c 'tty' 
not a tty

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2118095View Question on Stackoverflow
Solution 1 - CentosStéphane BruckertView Answer on Stackoverflow
Solution 2 - CentosSenthilView Answer on Stackoverflow
Solution 3 - CentosMr.ThanksView Answer on Stackoverflow
Solution 4 - CentosalvincView Answer on Stackoverflow
Solution 5 - Centosraok1997View Answer on Stackoverflow
Solution 6 - CentosAndyView Answer on Stackoverflow
Solution 7 - CentosleonView Answer on Stackoverflow
Solution 8 - CentosgaoitheView Answer on Stackoverflow