Building (and running) a custom HTTPD container image

Having used Apache HTTPD for a good portion of my professional career, and being responsible for explaining how OpenShift works, I decided to try and build an Apache HTTPD container from scratch. For follow on work, I want to see the environment, so the container is essentially wrapping a mod_wsgi APP that dumps the environment. I took some trial and error to get it to run. Here is the end result:

I’m building using a Docker file.

FROM centos:latest
 
MAINTAINER Adam Young
 
RUN yum -y install httpd mod_wsgi
RUN sed -i.bak 's/Listen 80/Listen 8080/' /etc/httpd/conf/httpd.conf
RUN sed -i.bak 's/    CustomLog/#    CustomLog/' /etc/httpd/conf/httpd.conf
 
 
COPY index.html /var/www/html/
COPY envvars.py   /var/www/cgi-bin/envvars.wsgi
RUN  chmod a+rx   /var/www/cgi-bin/envvars.wsgi
COPY krbocp.conf /etc/httpd/conf.d/
 
CMD /usr/sbin/httpd -D FOREGROUND
 
EXPOSE 8080

While I had wanted to keep all of the HTTPD configuration in an external file, it turns out I needed to turn a couple things off in the main file first. Hence the two sed lines. The first one:

sed -i.bak 's/Listen 80/Listen 8080/' /etc/httpd/conf/httpd.conf

Changes the port on which the container instance listens from 80 to 8080. Since my end state is going to be to run this in OpenShift, and I want OpenShift to provide TLS, port 8080 cleartext is OK for now.

The second sed line:

sed -i.bak 's/    CustomLog/#    CustomLog/' /etc/httpd/conf/httpd.conf

Turns off the default logging for the access_log file. I need to override tis later.

This is my simplistic mod_wsgi conf file:

PidFile /tmp/apache.pid
ErrorLog /dev/stderr
TransferLog /dev/stdout
 
 
 
<VirtualHost *>
    DocumentRoot /var/www/html
    WSGIScriptAlias /envvars /var/www/cgi-bin/envvars.wsgi
    <Directory /var/www/cgi-bin>
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>

I got to this via trial and error. The logging section was based on a hint from https://twitter.com/nazgullien. Thank You Very Much.

Here is the WSGI code itself.

from os import environ
 
def application(environ, start_response):
    status = '200 OK'
    output = b'<html><head><title>Environemnt Variables</title></head><body><dl>'
 
 
    keys = environ.keys()
    for key in keys:
        line = '<dt>%s</dt><dd> %s</dd>\n' % (key, repr(environ[key]))
        output += line.encode('utf-8')
    output += b'</dl></body></html>'
 
    response_headers = [('Content-type', 'text/html'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
 
    return [output]

The complete code repository is here. Last tested commit is 33f4bcfae23aba4b60cb485e52b11a07caa50a8f but this repo is going to keep moving, so don’t be surprised if it looks nothing like I describe above by the time you look.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.