docker - 在 Windows 上将标准输入管道传输到 docker exec
问题描述
我正在尝试将 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
这适用于bash
、ps
和 Git bash。
这个答案是我能找到的关于做什么-i
和-t
做什么的最佳参考(用我能理解的语言)。
-t
据此,我的猜测是,当管道输入内容时,您不能使用,因为-t
这意味着输入来自终端设备,但在这种情况下,输入是管道(它本身来自终端设备)。
推荐阅读
- php - 使用 curl PHP 获取 API
- android - 等待片段被附加
- ios - 管道中的 Azure DevOps Fastlane 实现
- python - 一次对多列进行一次热编码并附加到主数据集?
- javascript - JavaScript单页应用,表单提交后如何显示正确的HTML?
- discord.py - 这个禁令命令不起作用......我该如何解决它?
- r - 如何在图例中添加垂直斜线或在 R 的线图中写一些东西?
- javascript - 使用 JS 正则表达式获取没有特定后缀的字符串段
- visual-studio - 如何从 TFS Checkin 隐藏敏感信息
- discord - 反应中的角色