-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.mod_wsgi
More file actions
79 lines (64 loc) · 3.12 KB
/
Dockerfile.mod_wsgi
File metadata and controls
79 lines (64 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Alpine Linux - Python 3 and Apache/MOD_WSGI (NOT mod_wsgi-express)
# =============================================================================
# alpine lnux has very up-to-date python3 and it can be used as the base.
# =============================================================================
FROM python:3.6.6-alpine
# Report short python version, e.g. "3.6" for mod_wsgi build
# =============================================================================
ENV PYTHON_VERSION=3.6
# HTTP Proxy Settings
ENV http_proxy="http://one.proxy.example.com:8080"
ENV https_proxy="http://one.proxy.example.com:8080"
ENV HTTP_PROXY="http://one.proxy.example.com:8080"
ENV HTTPS_PROXY="http://one.proxy.example.com:8080"
USER root
# Add apache2 packages (alpine package manager apk)
# =============================================================================
RUN apk --update --no-cache add apache2 apache2-dev \
wget ca-certificates make gcc musl-dev
# Add mod_wsgi shared library compiled to this python3
# =============================================================================
ENV MOD_WSGI_VERSION=4.6.4
ENV MOD_WSGI_SRC_URL="https://github.com/GrahamDumpleton/mod_wsgi/archive/${MOD_WSGI_VERSION}.tar.gz"
RUN wget -O /usr/src/mod_wsgi.tar.gz "${MOD_WSGI_SRC_URL}" && \
tar -zxvf /usr/src/mod_wsgi.tar.gz -C /usr/src && \
rm /usr/src/mod_wsgi.tar.gz
WORKDIR /usr/src/mod_wsgi-${MOD_WSGI_VERSION}
ENV CFLAGS="-I/usr/local/include/python${PYTHON_VERSION}m/ -L/usr/local/lib/"
RUN ln -s /usr/lib/libpython${PYTHON_VERSION}m.so /usr/lib/libpython${PYTHON_VERSION}.so && \
./configure \
--with-python=/usr/local/bin/python${PYTHON_VERSION} \
--with-apxs=/usr/bin/apxs && \
make && make install clean
RUN rm -rf /usr/src/mod_wsgi-${MOD_WSGI_VERSION}
# Set Apache2 Configurations
# =============================================================================
# Create PID file directory for /run/apache2/httpd.pid
RUN mkdir -p /run/apache2
# Set Servername to something.
RUN sed -i -r 's@#Servername.*@Servername wsgi@i' /etc/apache2/httpd.conf
# Direct access and error logs to stderr for Docker.
RUN sed -i -r 's@(CustomLog .*)@\1\nTransferLog /dev/stderr@i' /etc/apache2/httpd.conf
RUN sed -i -r 's@Errorlog .*@Errorlog /dev/stderr@i' /etc/apache2/httpd.conf
# Direct *.wsgi scripts to mod_wsgi
RUN echo -e "\n\n\
LoadModule wsgi_module modules/mod_wsgi.so\n\
WSGIPythonPath /usr/lib/python${PYTHON_VERSION}\n\
Alias / /home/apache/\n\
<Directory /home/apache>\n\
Options ExecCGI FollowSymLinks\n\
AllowOverride All\n\
Require all granted\n\
AddHandler wsgi-script .wsgi\n\
</Directory>" >> /etc/apache2/httpd.conf
# "apache" runs a sample "hello world" WSGI script.
# =============================================================================
WORKDIR /home/apache
COPY ./hello.wsgi ./hello.wsgi
# Start Apache2 service without mod_wsgi-express
EXPOSE 80
CMD ["httpd", "-D", "FOREGROUND", "-e", "info"]
# =============================================================================
# Clean up the package index.
# =============================================================================
RUN rm -rf /var/cache/apk/*