From 65b25c5e05135e75eec84b3d51298075139a5f1e Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Fri, 23 Jan 2015 12:01:28 -0800 Subject: [PATCH 1/3] work in process --- README.md | 22 +++++++++++++++++++++- fig.yml | 6 ++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 09f71d5..652e47e 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Build the following containers (follow each link for instructions): `$ docker run -d -p 80:80 --name nginx-rp --volumes-from rp-data justadam/nginx-rp` -This gives us a nginx with a reverse proxy configuration (this file can be found at [docker-gen/templates/nginx.tmpl](docker-gen/templates/nginx.tmpl). The file will be updated by docker-gen each time a container stop or starts. +This gives us a nginx with a reverse proxy configuration (this file can be found at [docker-gen/templates/nginx.tmpl](docker-gen/templates/nginx.tmpl). The file will be updated by docker-gen each time a container stops or starts. Now we need a container to serve some content; this could be anything (apache, nginx, your own webserver), but we will be using a static content site generator named hugo, which also comes with its own webserver. Each container which is to sit behind the reverse proxy needs to set an environment variable called VHOST, which is the URL it will be serving content on. @@ -40,3 +40,23 @@ Each container which is to sit behind the reverse proxy needs to set an environm ### Start hugo `$ docker run -d --name hugo -e VHOST=www.before.no -v $(pwd):/content justadam/hugo:0.12` + +Testing +======= + +Nginx-rp looks at all web requests coming in, and routes to different containers based on the `Host` HTTP header sent by a web browser. In this way a single front end can automatically route between different sub-webservers. + +For testing, we need to pass our own `Host` header. Using boot2docker on OSX, this is: + + curl -i --header 'Host: example.com' $(boot2docker ip 2> /dev/null) + +The `example.com` matches `VHOST=example.com` in the top-level `fig.yml` file, therefore Nginx-rp routes the request to the `hello` Docker container. This container receives the request, and responds: + + HTTP/1.1 200 OK + Server: nginx/1.4.6 (Ubuntu) + Date: Wed, 21 Jan 2015 14:33:16 GMT + Content-Type: text/plain + Transfer-Encoding: chunked + Connection: keep-alive + + hello world diff --git a/fig.yml b/fig.yml index d03504e..71dd360 100644 --- a/fig.yml +++ b/fig.yml @@ -27,3 +27,9 @@ hugo: - ../websites/before.no/:/content environment: - VHOST=www.before.no +hello: + build: hello + command: python /hello.py hello world + environment: + - PORT=1234 + - VHOST=example.com From 15c0e0a79f5b47fbd5e5621b5c49f2fba98e1d01 Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Fri, 23 Jan 2015 12:01:41 -0800 Subject: [PATCH 2/3] work in process --- hello/Dockerfile | 7 +++++++ hello/hello.py | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 hello/Dockerfile create mode 100644 hello/hello.py diff --git a/hello/Dockerfile b/hello/Dockerfile new file mode 100644 index 0000000..3bbfa5a --- /dev/null +++ b/hello/Dockerfile @@ -0,0 +1,7 @@ +FROM ubuntu:14.04 + +ENV PYTHONUNBUFFERED 1 + +ADD hello.py / + +EXPOSE 1234 diff --git a/hello/hello.py b/hello/hello.py new file mode 100644 index 0000000..e6e612c --- /dev/null +++ b/hello/hello.py @@ -0,0 +1,21 @@ +import SimpleHTTPServer +import StringIO +import SocketServer +import os +import sys + +PORT = int(os.environ['PORT']) +MESSAGE = ' '.join(sys.argv[1:]) + +class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): + + def send_head(self): + self.send_response(200) + self.send_header("Content-type", 'text/plain') + self.end_headers() + return StringIO.StringIO(MESSAGE) + +httpd = SocketServer.TCPServer(("", PORT), MyHandler) + +print "serving at port", PORT +httpd.serve_forever() From afc7ac7aefbdbbd16c8f80e556b6a135a38f40e0 Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Fri, 23 Jan 2015 12:07:04 -0800 Subject: [PATCH 3/3] bugfix: use Python base image; move CMD to docker level --- fig.yml | 1 - hello/Dockerfile | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fig.yml b/fig.yml index 71dd360..0c2074b 100644 --- a/fig.yml +++ b/fig.yml @@ -29,7 +29,6 @@ hugo: - VHOST=www.before.no hello: build: hello - command: python /hello.py hello world environment: - PORT=1234 - VHOST=example.com diff --git a/hello/Dockerfile b/hello/Dockerfile index 3bbfa5a..86f94b4 100644 --- a/hello/Dockerfile +++ b/hello/Dockerfile @@ -1,7 +1,8 @@ -FROM ubuntu:14.04 +FROM python:2.7 ENV PYTHONUNBUFFERED 1 ADD hello.py / +CMD python /hello.py hello world EXPOSE 1234