【问题标题】:Pipe stdin to docker exec on Windows在 Windows 上将标准输入管道传输到 docker exec
【发布时间】:2021-01-11 14:15:38
【问题描述】:

我正在尝试将 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:/#

【问题讨论】:

    标签: docker exec stdin tty


    【解决方案1】:

    如果您删除 -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 意味着输入来自终端设备,但在这种情况下,输入是管道(它本身来自终端设备)。

    【讨论】:

      猜你喜欢
      • 2022-07-05
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多