昨天,今天,明天,每天的每天,你是否都多懂得一点点...

星期六, 四月 28, 2018

A quick HTTP server using python docker container

Navigate to the www dir which  you would like to use as web root

Create a new file call http.py (you can use any file name) with following content

import SimpleHTTPServer  import SocketServer    PORT = 8000    Handler = SimpleHTTPServer.SimpleHTTPRequestHandler    httpd = SocketServer.TCPServer(("", PORT), Handler)    print "serving at port", PORT  httpd.serve_forever()

Run the following test command


sudo docker run -it --rm --name my-running-script -p 8000:8000 -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:2 python http.py

Test:

root@fengUbuntu:~/certs# curl http://localhost:8000/http.py
import SimpleHTTPServer
import SocketServer

PORT = 8000

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)

print "serving at port", PORT
httpd.serve_forever()



--
Feng

没有评论:

其它博客地址

此博客的同步博客地址: http://fengnz.wordpress.com
这里进入我的MSN SPACE.