gpt4 book ai didi

docker - 在 Windows 上将标准输入通过管道传输到 docker exec

转载 作者:行者123 更新时间:2023-12-05 03:45:39 25 4
gpt4 key购买 nike

我正在尝试将 SQL 数据导入 docker 容器。使用 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

我也尝试过 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,在容器中运行 bash 工作正常:

> docker exec -it 79c5c16acca0 bash
root@79c5c16acca0:/#

最佳答案

如果您删除 -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

bashps 和 Git bash 都是如此。

answer是我能找到的关于 -i-t 功能的最佳引用(使用我能理解的语言)。

据此,我的猜测是当管道输入内容时不能使用 -t,因为 -t 暗示输入来自终端设备,但在此如果输入是管道(管道本身来自终端设备)。

关于docker - 在 Windows 上将标准输入通过管道传输到 docker exec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65668498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com