Skip to content

Commit 96b98d9

Browse files
committed
Replace manifest setup
Simplifies setup by removing manifest folder, flattening structure. * Replaces ini file with inline php-fpm conf settings * Fixes a number of issues around logging and the supervisor, see lsl/docker-nginx-php-fpm for more in depth details * Example updated to work with new changes * Hides favicon logging * Moves web root to /www from /var/www
1 parent 5e0976a commit 96b98d9

13 files changed

+141
-121
lines changed

.dockerignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.gitignore
1+
.gitignore
2+
example
3+
README.md

Dockerfile

+38-35
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,29 @@ RUN find /app/wordpress -type f -exec chmod 644 {} \;
2020
# Build image
2121
FROM alpine:3.7
2222

23-
# Set user
24-
# Note: implicitly creates: /var/www, www group @ gid 1000
25-
# Previously using -G wheel (this might get reverted)
26-
RUN adduser -D -u 1000 -g 1000 -s /bin/sh -h /var/www www-data
23+
# Create user
24+
RUN adduser -D -u 1000 -g 1000 -s /bin/sh www-data && \
25+
mkdir -p /www && \
26+
chown -R www-data:www-data /www
2727

28-
# PHP/FPM + Modules
28+
# Install tini - 'cause zombies - see: https://github.com/ochinchina/supervisord/issues/60
29+
# (also pkill hack)
30+
RUN apk add --no-cache --update tini
31+
32+
# Install a golang port of supervisord
33+
COPY --from=ochinchina/supervisord:latest /usr/local/bin/supervisord /usr/bin/supervisord
34+
35+
# Install nginx & gettext (envsubst)
36+
# Create cachedir and fix permissions
37+
RUN apk add --no-cache --update \
38+
gettext \
39+
nginx && \
40+
mkdir -p /var/cache/nginx && \
41+
chown -R www-data:www-data /var/cache/nginx && \
42+
chown -R www-data:www-data /var/lib/nginx && \
43+
chown -R www-data:www-data /var/tmp/nginx
44+
45+
# Install PHP/FPM + Modules
2946
RUN apk add --no-cache --update \
3047
php7 \
3148
php7-apcu \
@@ -58,28 +75,13 @@ RUN apk add --no-cache --update \
5875
php7-zip \
5976
php7-zlib
6077

61-
# tini - 'cause zombies - see: https://github.com/ochinchina/supervisord/issues/60
62-
# gettext - nginx env substitution
63-
RUN apk add --no-cache --update \
64-
tini \
65-
gettext \
66-
nginx && \
67-
rm -rf /var/www/localhost
68-
69-
# Fix nginx dirs/perms
70-
RUN mkdir -p /var/cache/nginx && \
71-
chown -R www-data:www-data /var/cache/nginx && \
72-
chown -R www-data:www-data /var/lib/nginx && \
73-
chown -R www-data:www-data /var/tmp/nginx
74-
75-
# Install a golang port of supervisord
76-
COPY --from=ochinchina/supervisord:latest /usr/local/bin/supervisord /usr/bin/supervisord
77-
7878
# Runtime env vars are envstub'd into config during entrypoint
79-
# Defaults: proto: http, name: localhost, alias: ''
80-
ENV SERVER_PROTO='http'
81-
ENV SERVER_NAME='localhost'
82-
ENV SERVER_ALIAS=''
79+
ENV SERVER_PROTO="http"
80+
ENV SERVER_NAME="localhost"
81+
ENV SERVER_ALIAS=""
82+
83+
# Alias defaults to empty, example usage:
84+
# SERVER_ALIAS='www.example.com'
8385

8486
# Wordpress config settings
8587
ENV DB_NAME='wordpress'
@@ -100,16 +102,17 @@ ENV SECURE_AUTH_SALT='set me'
100102
ENV LOGGED_IN_SALT='set me'
101103
ENV NONCE_SALT='set me'
102104

103-
COPY /manifest /
104-
105-
COPY --from=composer --chown=www-data:www-data /app/wordpress /var/www/wordpress
105+
COPY ./supervisord.conf /supervisord.conf
106+
COPY ./php-fpm-www.conf /etc/php7/php-fpm.d/www.conf
107+
COPY ./nginx.conf.template /nginx.conf.template
108+
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
109+
COPY ./salt /usr/bin/salt
106110

107-
COPY --chown=www-data:www-data wp-config.php /var/www/wordpress/wp-config.php
108-
109-
WORKDIR /var/www/wordpress
111+
COPY --from=composer --chown=www-data:www-data /app/wordpress /www/wordpress
112+
COPY --chown=www-data:www-data ./wp-config.php /www/wordpress/wp-config.php
110113

114+
# Nginx on :80
111115
EXPOSE 80
112-
116+
WORKDIR /www
113117
ENTRYPOINT ["tini", "--"]
114-
CMD ["/docker-entrypoint.sh"]
115-
118+
CMD [ "/docker-entrypoint.sh" ]

manifest/docker-entrypoint.sh renamed to docker-entrypoint.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ SERVER_PROTO=${SERVER_PROTO:-http}
55
SERVER_NAME=${VIRTUAL_HOST:-${SERVER_NAME:-localhost}}
66
SERVER_ALIAS=${SERVER_ALIAS:-''}
77

8-
envsubst '$SERVER_NAME $SERVER_ALIAS' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf
8+
envsubst '$SERVER_NAME $SERVER_ALIAS' < /nginx.conf.template > /etc/nginx/nginx.conf
99

1010
# WordPress subs
1111
WP_SITE_URL=${WP_SITE_URL:-$SERVER_PROTO://$SERVER_NAME}
1212
WP_HOME=${WP_HOME:-$WP_SITE_URL}
1313

14-
supervisord -c /etc/supervisord.conf
14+
supervisord -c /supervisord.conf

example/docker-compose.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ services:
2626
web:
2727
build: ./site
2828
volumes:
29-
- uploads:/var/www/wordpress/wp-content/uploads:rw
29+
- uploads:/www/wordpress/wp-content/uploads:rw
3030
environment:
3131
VIRTUAL_HOST: "example.localhost"
32+
SERVER_PROTO: "http"
3233
DB_NAME: wordpress
3334
DB_USER: wordpress
3435
DB_PASSWORD: wordpress
3536
DB_HOST: mysql
36-
WP_DEBUG: 'false'
37+
WP_DEBUG: "true"
3738

3839
# Database
3940
mysql:

example/site/.dockerignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
vendor
2-
wp-content
2+
wp-content
3+
README.md
4+
.gitignore

example/site/Dockerfile

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
FROM lslio/composer:latest as composer
22

33
COPY ./composer.* /app/
4-
RUN composer-install
5-
6-
# Must use plugins (auto enable)
7-
RUN mv /app/wordpress/wp-content/plugins/all-in-one-wp-migration /app/wordpress/wp-content/mu-plugins/all-in-one-wp-migration
8-
RUN mv /app/wordpress/wp-content/plugins/lcache /app/wordpress/wp-content/mu-plugins/lcache
4+
RUN composer-install -d /app
95

106
# Final Build
117
FROM lslio/wordpress:latest
@@ -32,9 +28,9 @@ ENV SECURE_AUTH_SALT='?!LQjInJJf+HRBN!1mA7[iyRZICG=!lBW(]fC5|1Q52RzY>3-]Y3q*XBv2
3228
ENV LOGGED_IN_SALT='v2y2x%|cHs6v*thfr~MZG~[MNB-`r9Y~X_ ]f-Q9POmXu-3)p.Juo2-QC!hc^$IL'
3329
ENV NONCE_SALT='0zK_Ww(ljs]w?GHm}6as]w^_wP%!3Jc<~,Dt3pxS{`Rg$$9tsM[aRz$DL^KHW+Kp'
3430

35-
COPY --from=composer --chown=www:www /app/wp-content /var/www/wordpress/wp-content
31+
COPY --from=composer --chown=www-data:www-data /app/wp-content /www/wordpress/wp-content
3632

3733
# lcache needs some help
38-
USER www
39-
RUN ln -s /var/www/wordpress/wp-content/mu-plugins/wp-lcache/object-cache.php /var/www/wordpress/wp-content/object-cache.php
34+
USER www-data
35+
RUN ln -s /www/wordpress/wp-content/mu-plugins/wp-lcache/object-cache.php /www/wordpress/wp-content/object-cache.php
4036
USER root

manifest/etc/php7/conf.d/zz_php.ini

-11
This file was deleted.

manifest/etc/php7/php-fpm.d/www.conf

-24
This file was deleted.

manifest/etc/supervisord.conf

-30
This file was deleted.

manifest/etc/nginx/nginx.conf.template renamed to nginx.conf.template

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
daemon off;
21

3-
user www-data;
4-
5-
worker_processes 4;
62

73
pid /run/nginx.pid;
84

9-
error_log /dev/stderr;
5+
user www-data;
6+
7+
worker_processes auto;
8+
9+
error_log /dev/stderr info;
1010

1111
events {
1212
worker_connections 2048;
@@ -35,7 +35,9 @@ http {
3535

3636
open_file_cache max=100;
3737

38-
access_log /dev/stdout;
38+
log_format docker '$remote_addr $remote_user $status "$request" "$http_referer" "$http_user_agent" ';
39+
40+
access_log /dev/stdout docker;
3941

4042
include /etc/nginx/mime.types;
4143

@@ -45,7 +47,7 @@ http {
4547

4648
server_name $SERVER_NAME $SERVER_ALIAS;
4749

48-
root /var/www/wordpress;
50+
root /www/wordpress;
4951

5052
index index.php;
5153

@@ -64,5 +66,10 @@ http {
6466
location ~ /\.ht {
6567
deny all;
6668
}
69+
70+
location ~ ^/favicon {
71+
log_not_found on;
72+
access_log off;
73+
}
6774
}
6875
}

php-fpm-www.conf

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[global]
2+
daemonize = no
3+
; stdout and stderr (/proc/self/fd/2) is routed to /proc/1/fd/2 via supervisord, as in process logs are output to docker output
4+
error_log = /dev/stderr
5+
log_level = notice
6+
7+
[www]
8+
user = www-data
9+
group = www-data
10+
11+
; Ignore these settings - dodgy php-fpm error handling is worked around
12+
; with the error_log directive below
13+
;access.log = /dev/stderr
14+
;access.format = "%R %u %s \"%m %r\""
15+
16+
; Turning this on results in a double up of error logs, once for the worker, and secondarily for php-fpm. Instead we skip both and go straight to /proc/1/fd/2 via error_log set below.
17+
catch_workers_output = no
18+
19+
clear_env = no
20+
21+
listen = /run/php-fpm.sock
22+
listen.owner = www-data
23+
listen.group = www-data
24+
listen.mode = 0660
25+
26+
pm = ondemand
27+
pm.process_idle_timeout = 10s
28+
pm.max_requests = 1000
29+
30+
; Edited by /auto-fpm.sh
31+
pm.max_children = 5
32+
pm.max_spare_servers = 30
33+
34+
; Admin settings can't be overridden
35+
php_admin_flag[log_errors] = on
36+
php_admin_value[log_errors_max_len] = 4096
37+
php_admin_value[error_log] = /proc/1/fd/2
38+
39+
; Normals can be
40+
php_flag[display_errors] = off
41+
php_value[date.timezone] = UTC
42+
43+
; this should match FPM_PROCESS_MEMORY_MB in /auto-fpm.sh
44+
php_value[memory_limit] = 128M
45+
php_value[upload_max_filesize] = 512M
46+
php_value[post_max_size] = 50M
47+
php_value[default_socket_timeout] = 300
48+
File renamed without changes.

supervisord.conf

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; All logging should be output on pid 1 fd 1 (stdout of tini)
2+
; Run everything foreground and kill supervisord if either fail
3+
4+
[supervisord]
5+
nodaemon=true
6+
logfile=/dev/stdout
7+
logfile_maxbytes=0
8+
loglevel=warn
9+
user=root
10+
pidfile=/run/supervisord.pid
11+
12+
[program:php-fpm]
13+
command=/bin/sh -c "php-fpm7 --nodaemonize || (echo 'php-fpm exited.' && pkill -9 supervisord)"
14+
autostart=true
15+
priority=5
16+
stdout_logfile=/dev/stdout
17+
stdout_logfile_maxbytes=0
18+
redirect_stderr=true
19+
20+
[program:nginx]
21+
command=/bin/sh -c "nginx -g 'daemon off;' || (echo 'nginx exited.' && pkill -9 supervisord)"
22+
autostart=true
23+
priority=10
24+
stdout_logfile=/dev/stdout
25+
stdout_logfile_maxbytes=0
26+
redirect_stderr=true

0 commit comments

Comments
 (0)