Create a gist now

Instantly share code, notes, and snippets.

@jmorton /Dockerfile
Last active Jul 11, 2017

What would you like to do?
Install Python 3.4.2 + mod_wsgi on CentOS
docker build --tag="jmorton/apache-python3-wsgi"
docker run -it jmorton/python /bin/bash
FROM centos:centos6
MAINTAINER jmorton@usgs.gov
# Apache
RUN yum install -y httpd httpd-devel
RUN chkconfig httpd on
RUN apachectl start
# Dependencies
RUN yum groupinstall -y "Development tools"
RUN yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline
RUN yum install -y tar
# Python 3.4.2
WORKDIR /usr/local/src
RUN curl -O https://www.python.org/ftp/python/3.4.2/Python-3.4.2.tgz
RUN tar -xvzf Python-3.4.2.tgz
WORKDIR /usr/local/src/Python-3.4.2
RUN ./configure --enable-shared --prefix=/usr/local LDFLAGS="-Wl,-rpath /usr/local/lib"
RUN make
RUN make altinstall
RUN apachectl restart
# mod_wsgi python package
RUN pip3.4 install mod_wsgi
RUN mod_wsgi-express install-module
RUN pyvenv-3.4 /var/www/venv
RUN mkdir -p /var/www/apps
ADD wsgi.conf /etc/httpd/conf.d/
ADD apps /var/www/apps
# Deployment
RUN yum -y install openssh-server openssh-clients
RUN chkconfig sshd on
RUN service sshd start
RUN useradd deploy
RUN chown -R deploy:deploy /var/www/
RUN find /var/www/apps -type f -exec chmod 640 {} \;
RUN find /var/www/apps -type d -exec chmod 750 {} \;
EXPOSE 22 80 443
LoadModule wsgi_module /etc/httpd/modules/mod_wsgi-py34.cpython-34m.so
WSGIPythonHome /var/www/venv
WSGIDaemonProcess flask user=deploy group=deploy
WSGIProcessGroup flask
WSGISocketPrefix /var/run/wsgi
Alias /apps /var/www/apps/
<Directory /var/www/apps/>
Options ExecCGI MultiViews Indexes
MultiViewsMatch Handlers
AddHandler wsgi-script .py
AddHandler wsgi-script .wsgi
DirectoryIndex index.html index.php index.py app.wsgi
Order allow,deny
Allow from all
</Directory>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment