Skip to content

Commit 5e0976a

Browse files
committed
init
0 parents  commit 5e0976a

File tree

18 files changed

+547
-0
lines changed

18 files changed

+547
-0
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.gitignore

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.lock
2+
vendor
3+
wp-content

Dockerfile

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
FROM lslio/composer:latest as composer
2+
3+
# Installs WordPress into /app/wordpress
4+
RUN composer-require johnpbloch/wordpress:^4.9
5+
6+
# Delete hello dolly
7+
RUN rm /app/wordpress/wp-content/plugins/hello.php
8+
9+
# Create uploads + mu-plugins dirs
10+
# Note: if you don't do this here, later when you
11+
# mount /uploads it will have root permissions
12+
# preventing uploads etc
13+
RUN mkdir /app/wordpress/wp-content/uploads
14+
RUN mkdir /app/wordpress/wp-content/mu-plugins
15+
16+
# Fix write perms, ownership fixed on copy
17+
RUN find /app/wordpress -type d -exec chmod 755 {} \;
18+
RUN find /app/wordpress -type f -exec chmod 644 {} \;
19+
20+
# Build image
21+
FROM alpine:3.7
22+
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
27+
28+
# PHP/FPM + Modules
29+
RUN apk add --no-cache --update \
30+
php7 \
31+
php7-apcu \
32+
php7-bcmath \
33+
php7-bz2 \
34+
php7-ctype \
35+
php7-curl \
36+
php7-dom \
37+
php7-fpm \
38+
php7-ftp \
39+
php7-gd \
40+
php7-iconv \
41+
php7-json \
42+
php7-mbstring \
43+
php7-mysqli \
44+
php7-oauth \
45+
php7-opcache \
46+
php7-openssl \
47+
php7-pcntl \
48+
php7-pdo \
49+
php7-pdo_mysql \
50+
php7-phar \
51+
php7-redis \
52+
php7-session \
53+
php7-simplexml \
54+
php7-tokenizer \
55+
php7-xdebug \
56+
php7-xml \
57+
php7-xmlwriter \
58+
php7-zip \
59+
php7-zlib
60+
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+
78+
# 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=''
83+
84+
# Wordpress config settings
85+
ENV DB_NAME='wordpress'
86+
ENV DB_USER='wordpress'
87+
ENV DB_PASSWORD='wordpress'
88+
ENV DB_HOST='mysql'
89+
ENV WP_DEBUG='false'
90+
91+
# These need to be set in your extending Dockerfile
92+
# `docker run --rm lslio/wordpress salt`
93+
# (its a wrapper around https://api.wordpress.org/secret-key/1.1/salt/)
94+
ENV AUTH_KEY='set me'
95+
ENV SECURE_AUTH_KEY='set me'
96+
ENV LOGGED_IN_KEY='set me'
97+
ENV NONCE_KEY='set me'
98+
ENV AUTH_SALT='set me'
99+
ENV SECURE_AUTH_SALT='set me'
100+
ENV LOGGED_IN_SALT='set me'
101+
ENV NONCE_SALT='set me'
102+
103+
COPY /manifest /
104+
105+
COPY --from=composer --chown=www-data:www-data /app/wordpress /var/www/wordpress
106+
107+
COPY --chown=www-data:www-data wp-config.php /var/www/wordpress/wp-config.php
108+
109+
WORKDIR /var/www/wordpress
110+
111+
EXPOSE 80
112+
113+
ENTRYPOINT ["tini", "--"]
114+
CMD ["/docker-entrypoint.sh"]
115+

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# WordPress + PHP-FPM7 + Nginx + Alpine Linux
2+
3+
Simplifying WordPress deployment leveraging docker.
4+
5+
.. That's the plan anyway.
6+
7+
Current state comes with a lot of technical caveats.
8+
9+
This is not a fork or replacement for the Official [WordPress](https://hub.docker.com/_/wordpress/) image.
10+
11+
This image aims to solve the problems you face when deploying a single WordPress image over a k8's cluster or docker swarm.
12+
13+
This image is *not* intended to be used stand-alone, while it comes with a working wordpress install it is intended as a base to install plugins and themes overtop. To use standalone you would need to mount your own wp-content folder into the container at runtime.
14+
15+
Current limitations:
16+
- wp-content/uploads needs to be mounted to something like NFS for use on multi-server setups.
17+
- Plugins that leverage disk for caching need to be avoided (e.g. w3-total-cache, fvm, autoptimize.)
18+
- plugins and themes need to be pre-installed with composer.
19+
- wp-cli is out due to requiring an unattainable db connection.
20+
21+
The nginx/php-fpm setup is based off of [lslio/nginx-php-fpm](https://github.com/lsl/docker-nginx-php-fpm) but does not extend from it so we have some room to make customizations for WordPress.
22+
23+
To work around the limitations it is expected users either run a build step on their themes / plugins prior to building the docker image or make use of external services to handle minification and other optimizations.
24+
25+
A potential addition to this project might be a pre-configured varnish image that is automatically aware / linked to this image.
26+
27+
## [Quickstart example](https://github.com/lsl/docker-wordpress/tree/master/example)
28+
29+
```
30+
git clone [email protected]:lsl/docker-wordpress.git
31+
cd docker-wordpress/example
32+
docker-compose up -d
33+
xdg-open http://example.localhost
34+
```
35+
36+
## [Docker Pull](https://hub.docker.com/r/lslio/wordpress/)
37+
38+
```
39+
docker pull lslio/wordpress
40+
```
41+
42+

example/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Example lslio/wordpress setup
2+
3+
## Quickstart
4+
5+
```
6+
git clone https://github.com/lsl/docker-wordpress
7+
cd docker-wordpress/example
8+
docker-compose up -d
9+
xdg-open http://example.localhost
10+
```
11+
12+
This is a simple example of how you might use [lslio/wordpress](https://hub.docker.com/r/lslio/wordpress/) in a development environment.
13+
14+
The docker-compose.yml contains a reverse proxy, wordpress, and mysql containers. The reverse proxy could be removed if you only have one wordpress install you want to manage through this file.
15+
16+
## Salts
17+
18+
site/Dockerfile is an example Dockerfile you might use to build your own WordPress image.
19+
20+
Run `docker run --rm lslio/wordpress salt` and copy the output into site/Dockerfile
21+
22+
23+
## Secrets in Environment Variables
24+
25+
Currently DB_PASSWORD is stored as an environment variable, along with AUTH_KEY and salts.
26+
27+
Fixing this would probably take a decent chunk of time where anyone serious enough could easily solve the problem by dropping in a secrets mount over /var/www/wordpress/wp-config.php.

example/docker-compose.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# https://docs.docker.com/compose/compose-file/compose-versioning/
2+
version: '3.6'
3+
4+
# Use `docker-compose down --volumes` to clear.
5+
volumes:
6+
mysql: # MySQL data dir
7+
uploads: # wp-content/uploads dir
8+
9+
services:
10+
# Isn't required but nice to have if you're working on
11+
# or modifying the main image.
12+
base:
13+
image: lslio/wordpress
14+
build: ../
15+
entrypoint: /bin/true
16+
17+
# Reverse proxy
18+
nginx-proxy:
19+
image: jwilder/nginx-proxy
20+
ports:
21+
- "80:80"
22+
volumes:
23+
- /var/run/docker.sock:/tmp/docker.sock:ro
24+
25+
# Web service
26+
web:
27+
build: ./site
28+
volumes:
29+
- uploads:/var/www/wordpress/wp-content/uploads:rw
30+
environment:
31+
VIRTUAL_HOST: "example.localhost"
32+
DB_NAME: wordpress
33+
DB_USER: wordpress
34+
DB_PASSWORD: wordpress
35+
DB_HOST: mysql
36+
WP_DEBUG: 'false'
37+
38+
# Database
39+
mysql:
40+
image: mariadb:10.3.5
41+
volumes:
42+
- mysql:/var/lib/mysql # Local volume mount for persistence
43+
command: ["mysqld", "--default-time-zone=+00:00"]
44+
environment:
45+
MYSQL_ROOT_PASSWORD: root
46+
MYSQL_DATABASE: wordpress
47+
MYSQL_USER: wordpress
48+
MYSQL_PASSWORD: wordpress

example/site/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
wp-content

example/site/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
wp-content

example/site/Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM lslio/composer:latest as composer
2+
3+
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
9+
10+
# Final Build
11+
FROM lslio/wordpress:latest
12+
13+
# Used by nginx + wordpress
14+
ENV SERVER_PROTO=https
15+
ENV SERVER_NAME=example.com
16+
ENV SERVER_ALIAS=www.example.com
17+
18+
# Used by Wordpress
19+
ENV DB_NAME='wordpress'
20+
ENV DB_USER='wordpress'
21+
ENV DB_PASSWORD='wordpress'
22+
ENV DB_HOST='mysql'
23+
ENV WP_DEBUG='false'
24+
25+
# Generate your own salts with docker run --rm lslio/wordpress salt
26+
ENV AUTH_KEY='-GM.Sk1gRDV2}D?+`beZ}Cty?v,#rZ|a--z.l?_7HgWMu)&8S(oC~2u.ECGC3+=X'
27+
ENV SECURE_AUTH_KEY='D_ADN1@kx`FWYv6IQ*UnnD!T]pIZT67U+HlX58/p(mSb~&]Gr->@Z%%l8@t-uyZ*'
28+
ENV LOGGED_IN_KEY='k0ap|!f*jL_S_0Ks5C-q9=mGN#BEr7h/m4`3!::5=5 [~:A>+F!qL2*jqlkOy`UB'
29+
ENV NONCE_KEY='`;dYKh+{K=>!;# 8-kt-Km>~1+s97L|-mUd5QC4q%}J}wW`.hIN~{/(={xUb{=Ro'
30+
ENV AUTH_SALT='Vs&/=u3`sG:uw0WDp8%b-Y6~ =_UJ+ Oc47BK##HAxL}8v3D,t_+L2A!=HU|SD`a'
31+
ENV SECURE_AUTH_SALT='?!LQjInJJf+HRBN!1mA7[iyRZICG=!lBW(]fC5|1Q52RzY>3-]Y3q*XBv2h)(Mg2'
32+
ENV LOGGED_IN_SALT='v2y2x%|cHs6v*thfr~MZG~[MNB-`r9Y~X_ ]f-Q9POmXu-3)p.Juo2-QC!hc^$IL'
33+
ENV NONCE_SALT='0zK_Ww(ljs]w?GHm}6as]w^_wP%!3Jc<~,Dt3pxS{`Rg$$9tsM[aRz$DL^KHW+Kp'
34+
35+
COPY --from=composer --chown=www:www /app/wp-content /var/www/wordpress/wp-content
36+
37+
# 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
40+
USER root

example/site/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Example Site Dockerfile
2+
3+
This setup assumes you're in a position to pre-load plugins via composer and keep them up to date that way.
4+
5+
This setup has been designed with two main approaches in mind. Using this folder as a project folder and doing everyhing here, or having devops maintain this Docker setup and importing existing theme/plugin projects via composer.
6+
7+
Either approach should start with a run of composer update to setup your composer.lock file, this speeds up builds and lets others get up to speed quicker.
8+
9+
The resulting vendor and wp-content dirs are gitignored and dockerignored intentionally but for development you can mount them via docker-compose.yml.
10+
11+
If you need to make edits to specific 3rd party plugin you could check out their source tree into ./ and copy it in via the Dockerfile. I advise not to make random edits to things in vendor/wp-content and then commit them.

0 commit comments

Comments
 (0)