Skip to content

Instantly share code, notes, and snippets.

@JuanjoSalvador
Last active January 27, 2021 15:09
Show Gist options
  • Save JuanjoSalvador/b133254d89b7aec8259f387149b6f2ae to your computer and use it in GitHub Desktop.
Save JuanjoSalvador/b133254d89b7aec8259f387149b6f2ae to your computer and use it in GitHub Desktop.
Yet Another Docker Example. Now with Python!

How to run it

$ docker build -t yade -f Dockerfile
$ docker run --network host -d --rm -p 8000:8000 yade
$ curl localhost:8000

Explanation:

  • --network host allows Docker to use network-based functions, in host mode.
  • -d runs Docker as daemon (running at the background)
  • --rm removes the container if exited
  • -p 8000:8000 port-forwarding for container:8000 to host:8000

This should output something like this:

juanjo@debian:~/Docker$ curl localhost:8000
Hello world!
from http.server import BaseHTTPRequestHandler, HTTPServer
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(b'Hello world!')
if __name__ == '__main__':
server = HTTPServer(('localhost', 8000), Handler)
print("Server running on port 8000.")
server.serve_forever()
FROM alpine:latest
MAINTAINER Juanjo Salvador "[email protected]"
RUN apk add python3
COPY ./app.py /app/app.py
ENTRYPOINT ["python3", "/app/app.py"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment