1 Star 0 Fork 2

sunny/docker-console

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.py 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
lanbiter 提交于 2017-02-08 03:41 . fix ping and tail
from flask import Flask
from flask import render_template
from flask_sockets import Sockets
import docker
import time
import configure
from thread_send import threadSend
app = Flask(__name__)
sockets = Sockets(app)
docker_client = docker.Client(base_url=configure.DOCKER_HOST,
version=configure.DOCKER_API_VERSION,timeout=configure.TIME_OUT)
@app.route('/')
def hello_world():
return render_template('index.html')
def create_exec():
command = ["/bin/sh","-c",'TERM=xterm-256color; export TERM; [ -x /bin/bash ] && ([ -x /usr/bin/script ] && /usr/bin/script -q -c "/bin/bash" /dev/null || exec /bin/bash) || exec /bin/sh']
create_exec_options = {
"tty": True,
"stdin": True,
}
exec_id = docker_client.exec_create(configure.CONTAINER_ID, command, **create_exec_options)
return exec_id
@sockets.route('/echo')
def echo_socket(ws):
exec_id = create_exec()
sock = docker_client.exec_start(exec_id, detach=False, tty=True, stream=False,
socket=True)
sock.settimeout(600)
send = threadSend(ws,sock)
send.start()
while not ws.closed:
message = ws.receive()
if message is not None:
sock.send(message)
if __name__ == '__main__':
from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler
server = pywsgi.WSGIServer(('', 5000), app, handler_class=WebSocketHandler)
server.serve_forever()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/sunnydoy/docker-console.git
git@gitee.com:sunnydoy/docker-console.git
sunnydoy
docker-console
docker-console
master

搜索帮助