docker部署服务注意端口设置

浪子不回头ぞ 提交于 2020-01-14 23:48:16

在已有的容器中启动了一个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}}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!