Skip to content

Instantly share code, notes, and snippets.

@glynnforrest
Created October 16, 2016 19:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glynnforrest/972dd33b89bb77755a76b43f9dcdcb5d to your computer and use it in GitHub Desktop.
Save glynnforrest/972dd33b89bb77755a76b43f9dcdcb5d to your computer and use it in GitHub Desktop.
Http hello world docker container

Usage

docker build -t tiny-http . && docker run -ti -p 8080:8080 tiny-http
curl localhost:8080

Image size

docker ps

REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
tiny-http                     latest              14c6fc12c0b5        16 minutes ago      8.487 MB
FROM elyase/staticpython
COPY ./serve.py /
EXPOSE 8080
ENTRYPOINT ["/serve.py"]
#!/usr/bin/env python
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
PORT = 8080
class handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
self.wfile.write("Hello World!")
return
try:
server = HTTPServer(('', PORT), handler)
print 'listening on port' , PORT
server.serve_forever()
except KeyboardInterrupt:
server.socket.close()
@Kiran01bm
Copy link

The serve.py fails with the attached error. To fix the error changed the

self.wfile.write("Hello World!")

to

self.wfile.write("Hello World!".encode())

screen shot 2018-09-17 at 5 57 34 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment