60

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" 
Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
user2118095
  • 763
  • 1
  • 7
  • 13

8 Answers8

87

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
Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
  • 1
    Using -i or -t (or -it) I still had a problem. docker exec tty bug: https://github.com/docker/docker/issues/8755 workaround there suggests using docker exec -it CONTAINER script -qc COMMAND. I'm running docker exec -it under jenkins jobs and getting error 'cannot enable tty mode on non tty input'. – gaoithe Jul 27 '16 at 15:41
  • 1
    Actually I found my problem traced back to how ssh under jenkins shell was done. Using ssh -T flag (disable pseudo tty generation) helped solve my problem. – gaoithe Jul 28 '16 at 11:03
14

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

Senthil
  • 1,499
  • 16
  • 17
9

just use "-i"

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

Mr.Thanks
  • 215
  • 3
  • 7
8

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.

alvinc
  • 385
  • 3
  • 10
5

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
raok1997
  • 369
  • 5
  • 12
4

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

Community
  • 1
  • 1
Andy
  • 35,844
  • 6
  • 43
  • 50
  • Correct. I am running this command from Continous Integration Tool as( shell command). However when I run the same command on directly on the same machine's terminal window everything works find. When I ran the [[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive' command on the terminal I got the response as Interactive but when I ran the same command on the same machine from CI tool i got Non-Interactive. How can I fix that?. it's a centos 6.6 box. – user2118095 Apr 02 '15 at 19:05
  • Regarding the "run" & 'exec', my container is already running. So when I do docker ps -a I see my container is running however when I try to Run a command in an existing container I get the above error. Thanks for all your help! – user2118095 Apr 02 '15 at 19:15
  • Hey user2118095, are you able to find any solutions, the same is happening for me. – Sheesh Mohsin Jul 25 '15 at 18:47
  • @user2118095 did you get a solution for this? Would be great if you could share the solution if you were able to solve this. – user320550 Nov 16 '16 at 02:47
3

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:/#

leon
  • 1,012
  • 9
  • 11
0

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
gaoithe
  • 4,218
  • 3
  • 30
  • 38