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()
You can also run
sudo docker run the following docker command without creating a python file
-it –rm –name my-running-script -p 8000:8000 -v “$PWD”:/usr/src/myapp -w /usr/src/myapp python:2 python -m SimpleHTTPServer 8000