Categorygithub.com/wrfly/container-web-tty
modulepackage
0.1.11
Repository: https://github.com/wrfly/container-web-tty.git
Documentation: pkg.go.dev

# README

Container web TTY

Go Report Card Master Build Status GoDoc license Docker Pulls MicroBadger Size GitHub release Github All Releases

English

当我们想进入某个容器内部的时候,通常会执行这个命令组合 docker ps | grep xxx && docker exec -ti xxxx sh, 但老这样敲也是很烦,也许你可以试一下这个项目。

虽然我很喜欢终端,但是我仍然希望有一个更好的工具来进入容器内部去做一些检查或者debug。所以我写了这个项目,它能够帮助你通过点击网页的方式 进到容器里执行命令。初版的代码是基于yudai/gotty这个项目的,感谢yudai。

后端可以对接docker或者kubectl。

使用

你可以从release页面下载二进制运行这个程序,但这里有一些“复制粘贴”的方法。

通过 docker

docker.sock挂在到容器里就完事儿了

docker run --rm -ti --name web-tty \
    -p 8080:8080 \
    -v /var/run/docker.sock:/var/run/docker.sock \
    wrfly/container-web-tty

通过 kubernetes

你需要把kubernetes的配置文件挂进去,默认是在 $HOME/.kube/config,然后指定一下backed的类型,也就是kube

docker run --rm -ti --name web-tty \
    -p 8080:8080 \
    -e WEB_TTY_BACKEND=kube \
    -e WEB_TTY_KUBE_CONFIG=/kube.config \
    -v ~/.kube/config:/kube.config \
    wrfly/container-web-tty

通过 gRPC (代理模式)

当我们有很多server需要接入的时候,就可以使用这种模式把远程的container-web-ttymerge 到一起,典型的CS模式,通过gRPC通信。

在一个界面上查看多台机器上的容器。

远程配置

假如有两台机器 192.168.66.1192.168.66.2,他们可以用如下的命令来启动container-web-tty

docker run --rm -ti --name web-tty \
    -p 8080:8080 \
    -p 8090:8090 \
    -e WEB_TTY_GRPC_PORT=8090 \
    -e WEB_TTY_GRPC_AUTH=96ssW0rd \
    -v /var/run/docker.sock:/var/run/docker.sock \
    wrfly/container-web-tty

注意:

  • 你可以通过设置 WEB_TTY_PORT=-1 的方式来关闭HTTPserver,拒绝一般接入
  • 这个 WEB_TTY_GRPC_AUTH key 在所有机器上必须要相同(目前)

本地配置

docker run --rm -ti --name web-tty \
    -p 8080:8080 \
    -e WEB_TTY_BACKEND=grpc \
    -e WEB_TTY_GRPC_AUTH=96ssW0rd \
    -e WEB_TTY_GRPC_SERVERS=192.168.66.1:8090,192.168.66.2:8090 \
    wrfly/container-web-tty

现在你就可以通过访问 http://localhost:8080 来获取两台机器上所有的容器

快捷键 (Linux)

  • Cut the word before the cursor Ctrl+w => You cannot do it for now (I'll working on it for Ctrl+Backspace, but I know little about js)
  • Copy: Ctrl+Shift+c => Ctrl+Insert
  • Paste: Ctrl+Shift+v => Shift+Insert

特性

  • 能用了
  • 对接 docker 后端
  • 对接 kubectl 的后端
  • 比较好看的前端界面
  • start|stop|restart container(docker backend only)
  • 代理模式 (本地连接到远程机器上的容器)
  • 认证(仅限代理模式)
  • 超时自动断开
  • 历史记录审计
  • 实时共享输入输出
  • 容器日志
  • 自定义执行命令
  • 通过代理连接gRPC服务器

效果展示

列出所有容器:

list

在选择shell的时候,优选选择bash,如果没有,就依次选择ash,sh,再没有就退出了。

/bin/sh:

/bin/bash:

运行指定命令:

查看容器日志:

logs

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author