加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – Docker中终端内线路的Docker数量

发布时间:2020-12-15 19:05:15 所属栏目:安全 来源:网络整理
导读:我想知道如何更改以下行为。假设我的终端有28条线路。然后我使用以下命令: $ tput lines # my terminal28$ docker run --rm -it ubuntu:16.04 tput lines # docker container24 ## WHY??$ docker run --rm -it ubuntu:16.04 bash # docker container inside
我想知道如何更改以下行为。假设我的终端有28条线路。然后我使用以下命令:
$ tput lines # my terminal
28
$ docker run  --rm  -it ubuntu:16.04 tput lines  # docker container
24  ## WHY??
$ docker run  --rm  -it ubuntu:16.04 bash # docker container inside command
root@810effa2777c:/# tput lines
28

正如你所看到的,即使所有结果都应该是28,当我将容器称为docker run –rm -it ubuntu:16.04 tput lines时,尽管我的终端大小,它总是给我24。这不仅仅是ubuntu容器,我也试过debian(docker run –rm -it debian tput lines)并且我得到的结果相同24。

这样做的目的是使用mdp presentation tool,它考虑了终端中的线路。当我的实现失败时,我尝试了其他人的docker implementation,但我遇到了同样的错误。

这是我在图像中的错误:

有没有人知道它可能是什么以及如何解决这个问题?

Ubuntu Dockerfile包括:
CMD ["/bin/bash"]

这意味着默认的ENTRYPOINT是sh -c(我怀疑tput线在sh会话中运行良好,因为tput使用terminfo数据库,可能只为该图像中的bash设置)

您可以尝试用bash -c覆盖ENTRYPOINT并检查它是否更好。

但是,从命令行起,这不起作用:

docker run --entrypoint /bin/bash --rm  -it ubuntu:16.04 -i -c 'tput lines'
24

我将检查定义自定义图像的选项。

FROM ubuntu:16.04
ENTRYPOINT ["/bin/bash","-c"]

结果是相同的:

docker run --rm  -it u 'tput lines'
24

但这“有效”:

FROM ubuntu:16.04
ENTRYPOINT [ "/bin/bash" ]

附:

docker@default:/c/Users/vonc/prog/testsu$ docker run --rm  -it u -i -c 'ls; tput lines'
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
48

可能存在同步问题,因为同一命令会不时返回24。

实际上,以下内容始终返回“not 24”:

FROM ubuntu:16.04
ENTRYPOINT [ "/bin/bash","-l","-i","-c" ]

docker run --rm  -it u -c 'sleep 0.1; ls; tput lines'
48

OP silgon建议in the comments:

docker run --rm -it --entrypoint /bin/bash ubuntu:16.04 -c "sleep 0.1 && tput lines"

截至BMitch评论below:

Given the success of sleep my suspicion is that docker spins up the container with the running command,and once up,the client attaches to the running container.
Typically something that takes milliseconds.

这给了我另一个想法:

docker@default:/c/Users/vonc/prog/testsu$ 
docker run --entrypoint='/bin/bash' --name ub -d -it ubuntu:16.04
  0d9b8783afbb5e3ff4232da071d3f357985351ea1ce4d142bf6617ac456fb76b
docker@default:/c/Users/vonc/prog/testsu$ 
d attach ub
  root@0d9b8783afbb:/# tput lines
  48
  root@0d9b8783afbb:/# exit
exit
docker@default:/c/Users/vonc/prog/testsu$ drmae
0d9b8783afbb5e3ff4232da071d3f357985351ea1ce4d142bf6617ac456fb76b

附加会话中的输入行正常工作。
(关于drmae别名,请参阅“How to remove old and unused Docker images”)

thajeztah添加in the comments:

the container is created,then started with the defaults (80x24),and after that (when -it),a session is attached.
The session is specifying the size of the terminal;

请参见“Resize a container TTY”API。

DEBU[0244] Calling POST /v1.25/containers/c42fd5c4eb79c06fd7f9912b8359022f7d93887afbb33b57a67ed8bb7bfee4??3a/resize?h=46&w=221

有关更多信息,请参阅docker issue 25450。
它与issue 10341 “Container create or start should accept height/width params”有关.Aleksa Sarai (cyphar)补充(2016年9月):

This has actually popped up again inside the runtime-spec (070013).
Basically,since Windows requires the ability to set the console size on first start,we might end up adding it for all platforms.

OP silgon指出了api/client/container/run.go中的代码:

// Telling the Windows daemon the initial size of the tty during start makes
// a far better user experience rather than relying on subsequent resizes
// to cause things to catch up.
if runtime.GOOS == "windows" {
    hostConfig.ConsoleSize[0],hostConfig.ConsoleSize[1] = dockerCli.GetTtySize()
}

有逻辑的问题:

would it make sense to use this property on Linux as well,and set the initial console size using that value?

Kenfe-Micka?l Laventure (mlaventure)就在它上面,一个新的补丁可以到Docker 1.13。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读