在已有的容器中启动了一个etornado服务。
先查看该容器暴露的端口:
$ docker ps|grep gpu4
0f7eeff4f0f4 hub.ifchange.com/nlp/gpu4:20190917 "bash" 3 months ago Up 2 weeks 0.0.0.0:14006->6006/tcp, 0.0.0.0:14606->6606/tcp, 0.0.0.0:14888->8888/tcp gpu4
容器内部的端口有6006,6606,8888,随便选择一个没有被占用的端口6006(发送请求时对应的要使用14006端口),在 run_server.py
中设置好:
if __name__ == "__main__":
app = Application()
app.register_handler("/demo", TestHandler)
signal.signal(signal.SIGINT, lambda signum, frame, app=app: app.stop())
app.run(6006, 0)
在容器中启动服务:
\# python run_server.py
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
start service on port[6006], process_count[0], thread pool size[0] success!!!
在容器外部测试服务,正常运行:
$ curl http://127.0.0.1:14006/demo
{"response": {"err_no": 0, "err_msg": "ok", "results": "Hello, this is demo server."}}
$ curl -X POST -d 123 http://127.0.0.1:14006/demo
{"response": {"err_no": 0, "err_msg": "ok", "results": 123}}