Skip to content

Commit 9ed914f

Browse files
committed
Merge branch 'develop'
Initial release v0.1.0-RC1.
2 parents 767678f + d2cee80 commit 9ed914f

File tree

9 files changed

+415
-0
lines changed

9 files changed

+415
-0
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.editorconfig
2+
CHANGELOG.md
3+
LICENSE
4+
Makefile
5+
README.md

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.yml]
15+
indent_style = space
16+
indent_size = 2
17+
18+
[Makefile]
19+
indent_style = tab

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
TAG v0.1.0-RC1 (2016-12-01)
2+
3+
Initial release
4+
- Compile Nginx v1.11.6 from source
5+
- Compile PHP with PHP-FPM v7.0.13 from source.
6+
- Install most recent version of PHP composer (as of 2016-12-01 v1.2.2).
7+
- Install Honcho for process monitoring.

Dockerfile

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
FROM debian:jessie
2+
3+
ENV \
4+
NGINX_VERSION=1.11.6 \
5+
PHP_VERSION=7.0.13
6+
7+
COPY \
8+
docker-entrypoint \
9+
nginx.conf \
10+
Procfile \
11+
/tmp/build/scripts/
12+
13+
RUN \
14+
# Install tools, required for building
15+
apt-get update && \
16+
apt-get install -y --no-install-recommends \
17+
# In general...
18+
build-essential \
19+
curl \
20+
21+
# For Nginx
22+
libpcre3-dev \
23+
libssl-dev \
24+
25+
# For PHP
26+
bison \
27+
libbz2-dev \
28+
libcurl4-openssl-dev \
29+
libpng12-dev \
30+
libpq-dev \
31+
libreadline-dev \
32+
libxml2-dev \
33+
libxslt1-dev \
34+
pkg-config \
35+
re2c \
36+
37+
# For PHP composer
38+
git \
39+
40+
# For Honcho
41+
python \
42+
python-pip \
43+
python-pkg-resources && \
44+
45+
pip install honcho && \
46+
47+
# Prepare for building
48+
mkdir -p /tmp/build && \
49+
50+
mkdir -p /tmp/build/nginx/ && \
51+
cd /tmp/build/nginx && \
52+
53+
# Download Nginx
54+
curl -SLO https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
55+
56+
cd /tmp/build/nginx && \
57+
58+
# GPG keys from the main maintainers of Nginx
59+
# Source https://nginx.org/en/pgp_keys.html
60+
curl -SLO https://nginx.org/keys/nginx_signing.key && \
61+
gpg --import nginx_signing.key && \
62+
curl -SLO https://nginx.org/keys/aalexeev.key && \
63+
gpg --import aalexeev.key && \
64+
curl -SLO https://nginx.org/keys/is.key && \
65+
gpg --import is.key && \
66+
curl -SLO https://nginx.org/keys/mdounin.key && \
67+
gpg --import mdounin.key && \
68+
curl -SLO https://nginx.org/keys/maxim.key && \
69+
gpg --import maxim.key && \
70+
curl -SLO https://nginx.org/keys/sb.key && \
71+
gpg --import sb.key && \
72+
73+
# Verify signature
74+
curl -SLO https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz.asc && \
75+
gpg nginx-${NGINX_VERSION}.tar.gz.asc && \
76+
77+
cd /tmp/build/nginx && \
78+
# Unpack tarball
79+
tar -xvzf nginx-${NGINX_VERSION}.tar.gz && \
80+
81+
cd /tmp/build/nginx/nginx-${NGINX_VERSION} && \
82+
# Run configuration
83+
./configure \
84+
--group=www-data \
85+
--user=www-data \
86+
--with-file-aio \
87+
--with-http_gunzip_module \
88+
--with-http_gzip_static_module \
89+
--with-http_realip_module \
90+
--with-http_ssl_module \
91+
--with-http_v2_module \
92+
--with-pcre \
93+
--with-threads && \
94+
95+
cd /tmp/build/nginx/nginx-${NGINX_VERSION} && \
96+
# Start compiling and installing
97+
make -j$(nproc) build && \
98+
make modules && \
99+
make install && \
100+
101+
# Nginx configuration
102+
mv /tmp/build/scripts/nginx.conf /usr/local/nginx/conf/ && \
103+
104+
mkdir -p /tmp/build/php/ && \
105+
cd /tmp/build/php && \
106+
107+
# Download PHP
108+
curl -SLo php-${PHP_VERSION}.tar.gz http://ch1.php.net/get/php-${PHP_VERSION}.tar.gz/from/this/mirror && \
109+
110+
cd /tmp/build/php/ && \
111+
112+
# GPG keys from the release managers of PHP 7.0
113+
# Source https://secure.php.net/gpg-keys.php#gpg-7.0
114+
gpg --keyserver pgp.mit.edu/ --recv "1A4E 8B72 77C4 2E53 DBA9 C7B9 BCAA 30EA 9C0D 5763" && \
115+
gpg --keyserver pgp.mit.edu/ --recv "6E4F 6AB3 21FD C07F 2C33 2E3A C2BF 0BC4 33CF C8B3" && \
116+
117+
# Verify signature
118+
curl -SLo php-${PHP_VERSION}.tar.gz.asc http://ch1.php.net/get/php-${PHP_VERSION}.tar.gz.asc/from/this/mirror && \
119+
gpg php-${PHP_VERSION}.tar.gz.asc && \
120+
121+
cd /tmp/build/php && \
122+
# Unpack tarball
123+
tar -xvzf php-${PHP_VERSION}.tar.gz && \
124+
125+
cd /tmp/build/php/php-${PHP_VERSION} && \
126+
# Run configuration
127+
./configure \
128+
--enable-fpm \
129+
--enable-mbregex \
130+
--enable-mbstring \
131+
--enable-mbstring=all \
132+
--enable-opcache \
133+
--enable-sockets \
134+
--enable-zip \
135+
--enable-zip \
136+
--with-bz2 \
137+
--with-curl \
138+
--with-fpm-group=www-data \
139+
--with-fpm-user=www-data \
140+
--with-gd \
141+
--with-gettext \
142+
--with-openssl \
143+
--with-pcre-regex \
144+
--with-pdo-mysql \
145+
--with-pdo-pgsql \
146+
--with-readline \
147+
--with-xsl \
148+
--with-zlib && \
149+
150+
cd /tmp/build/php/php-${PHP_VERSION} && \
151+
# Compile, test and install
152+
make -j$(nproc) build && \
153+
make install && \
154+
155+
# Fix permissions
156+
chown -R www-data:www-data /usr/local/nginx/html && \
157+
158+
# Symlink Nginx binary
159+
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ && \
160+
161+
# Copy PHP-FPM configuration files
162+
cp /tmp/build/php/php-${PHP_VERSION}/sapi/fpm/php-fpm.conf /usr/local/etc/php-fpm.conf && \
163+
cp /tmp/build/php/php-${PHP_VERSION}/sapi/fpm/www.conf /usr/local/etc/www.conf && \
164+
cp /tmp/build/php/php-${PHP_VERSION}/php.ini-development /usr/local/php/php.ini && \
165+
166+
# Patch PHP-FPM for proper loading www.conf
167+
sed -Ei \
168+
-e 's/^;?\s*daemonize\s*=\s*yes/daemonize = no/' \
169+
-e 's/^;?\s*include=NONE\/etc\/php-fpm.d\/\*.conf/include=\/usr\/local\/etc\/www.conf/' \
170+
/usr/local/etc/php-fpm.conf && \
171+
172+
# Patch www.conf config connection establishment
173+
sed -Ei \
174+
-e 's/^;?\s*listen\s*=.*/listen = \/var\/run\/php-fpm.sock/' \
175+
-e 's/^;?\s*?\s*listen.owner\s*=.*/listen.owner = www-data/' \
176+
-e 's/^;?\s*?\s*listen.group\s*=.*/listen.group = www-data/' \
177+
-e 's/^;?\s*?\s*listen.mode\s*=.*/listen.mode = 0660/' \
178+
/usr/local/etc/www.conf && \
179+
180+
# Patch PHP config files on the fly
181+
sed -Ei \
182+
-e 's/^;?\s*expose_php\s*=.*/expose_php = Off/' \
183+
-e 's/^;?\s*cgi.fix_pathinfo\s*=.*/cgi.fix_pathinfo=0/' \
184+
-e 's/^;?\s*error_log\s*=.*/error_log = \/usr\/local\/nginx\/logs\/error-php.log/' \
185+
-e 's/^;?\s*date.timezone\s*=.*/date.timezone = \"UTC\"/' \
186+
-e 's/^;?\s*opcache.enable\s*=.*/opcache.enable = 1/' \
187+
-e 's/^;?\s*opcache.enable_cli\s*=.*/opcache.enable_cli=1/' \
188+
-e 's/^;?\s*opcache.memory_consumption\s*=.*/opcache.memory_consumption = 256/' \
189+
-e 's/^;?\s*opcache.max_accelerated_files\s=.*/opcache.max_accelerated_files = 10000/' \
190+
/usr/local/php/php.ini && \
191+
192+
# Install PHP composer
193+
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
194+
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'aa96f26c2b67226a324c27919f1eb05f21c248b987e6195cad9690d5c1ff713d53020a02ac8c217dbf90a7eacc9d141d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
195+
php composer-setup.php --install-dir=/usr/local/bin --filename=composer && \
196+
php -r "unlink('composer-setup.php');" && \
197+
198+
# Configure Honcho
199+
mv /tmp/build/scripts/Procfile / && \
200+
201+
# Add entrypoint for docker
202+
mv /tmp/build/scripts/docker-entrypoint / && \
203+
chmod +x /docker-entrypoint && \
204+
205+
# Final cleanup
206+
apt-get remove -y \
207+
bison \
208+
build-essential \
209+
curl \
210+
pkg-config \
211+
python-pip \
212+
re2c && \
213+
214+
apt-get autoremove -y && \
215+
216+
rm -rf /var/lib/apt/lists/* && \
217+
rm -rf /tmp/build
218+
219+
# Declare entrypoint
220+
ENTRYPOINT ["/docker-entrypoint"]
221+
222+
# Define default command
223+
CMD ["server"]
224+
225+
# Define Workdir
226+
WORKDIR "/usr/local/nginx/html"
227+
228+
# Exposing ports
229+
EXPOSE 80/tcp 443/tcp

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
REPO = janus1990
2+
IMAGE = docker-nginx-php
3+
VERSION = 0.1.0
4+
EXTRAVERSION = -RC1
5+
6+
IMAGE_FQN = $(REPO)/$(IMAGE):v$(VERSION)$(EXTRAVERSION)
7+
8+
.PHONY: build
9+
10+
default: build
11+
12+
build:
13+
docker build -t $(IMAGE_FQN) .

Procfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nginx: /usr/local/sbin/nginx
2+
phpfpm: /usr/local/sbin/php-fpm

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## nginx-php Dockerfile
2+
3+
This repository contains source code of [janus1990/docker-nginx-php/](https://hub.docker.com/r/janus1990/docker-nginx-php/).
4+
5+
## Content
6+
7+
Nginx and PHP are compiled in a specific version. Consult the [CHANGELOG.md](./CHANGELOG.md) file
8+
for further version details. [PHP Composer](https://getcomposer.org/) is already installed and ready
9+
for use.
10+
11+
The Nginx and PHP-FPM master processes are controlled by [Honcho](https://github.com/nickstenning/honcho).
12+
Honcho was chosen over Supervisor, because honcho will exit and kill the container if either Nginx
13+
or PHP's master process dye for any reason. If you want have to have the container restarted
14+
automatically, you may want to use
15+
[Docker's restart](https://docs.docker.com/engine/reference/run/#restart-policies---restart) policy.
16+
17+
## Usage
18+
19+
```bash
20+
docker run -v /path/to/php/source/:/usr/local/nginx/html/ janus1990/docker-nginx-php
21+
22+
# With restart policy
23+
docker run --restart=always -v /path/to/php/source/:/usr/local/nginx/html/ janus1990/docker-nginx-php
24+
```
25+
26+
## Todo
27+
28+
- Add [HEALTHCHECK](https://docs.docker.com/engine/reference/builder/#/healthcheck)
29+
- Extend [README.md](./README.md) with configuration (Procfile, nginx.conf...).
30+
- Add more support for composer in docker entrypoint.

docker-entrypoint

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Fix permission ownership
4+
chown -R www-data:www-data /usr/local/nginx/html/
5+
6+
# Create PHP error log if not present
7+
# touch /usr/local/nginx/logs/error-php.log
8+
# chown www-data:www-data /usr/local/nginx/logs/error-php.log
9+
10+
# Update PHP composer
11+
# Update PHP composer to most most recent version (as of now the current version is v1.2.2).
12+
# By default, we will try to update to the most recent version of PHP composer.
13+
# However, this blocks starting the initial process IF you have a bad or no Internet connection at
14+
# all. To avoid this, you can start the container with SKIP_COMPOSER_UPDATE env set to 1.
15+
if [[ $SKIP_COMPOSER_UPDATE != "1" ]]; then
16+
composer selfupdate -vvvn
17+
fi
18+
19+
if [[ $1 == "server" ]]; then
20+
exec honcho -d / start
21+
fi
22+
23+
exec "$@"

0 commit comments

Comments
 (0)