Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

Pipe stdin to docker exec on Windows

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...