3

I'm trying to import SQL data to a docker container. Using git bash / mintty:

> docker exec -it 79c5c16acca0 mysql -uusername -ppassword dbname
the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'

> winpty docker exec -it 79c5c16acca0 mysql -uusername -ppassword dbname
stdin is not a tty

I have also tried Powershell:

> Get-Content powo.sql | docker exec -it 79c5c16acca0 mysql -uusername -ppassword dbname
the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'

FWIW, running bash in the container works fine:

> docker exec -it 79c5c16acca0 bash
root@79c5c16acca0:/#
Joaquim d'Souza
  • 1,416
  • 2
  • 14
  • 25

1 Answers1

4

This will work if you remove -t.

$ docker run --rm --name example alpine sleep 100

$ docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                 NAMES
49968909e3e4   alpine    "sleep 100"              8 seconds ago    Up 7 seconds                          example

$ echo "hi" | docker exec -it example cat
the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'

$ echo "hi" | docker exec -i example cat
hi

This is true for bash, ps, and Git bash.

This answer is the best reference I can find on what -i and -t do (in language that I can understand).

From that, my guess is that you can't use -t when piping in content as -t implies the input is from a terminal device, but in this case the input is the pipe (which itself is from the terminal device).

Akhil Nair
  • 3,144
  • 1
  • 17
  • 32
  • For those using Docker Compose, you also need to pass `-T` (`--no-tty`) because `docker compose exec` allocates a TTY by default. – rjh Nov 02 '22 at 22:55