Skip to content

Commit 7e7ae07

Browse files
authored
Merge pull request #2057 from infosiftr/read-only-wordpress
Update WordPress documentation, especially to document read-only deployments
2 parents a90f80b + e78de99 commit 7e7ae07

File tree

1 file changed

+49
-18
lines changed

1 file changed

+49
-18
lines changed

wordpress/content.md

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ WordPress is a free and open source blogging tool and a content management syste
1212
$ docker run --name some-%%REPO%% --network some-network -d %%IMAGE%%
1313
```
1414

15-
The following environment variables are also honored for configuring your WordPress instance:
15+
The following environment variables are also honored for configuring your WordPress instance (by [a custom `wp-config.php` implementation](https://github.com/docker-library/wordpress/blob/master/wp-config-docker.php)):
1616

1717
- `-e WORDPRESS_DB_HOST=...`
1818
- `-e WORDPRESS_DB_USER=...`
@@ -33,13 +33,6 @@ $ docker run --name some-%%REPO%% -p 8080:80 -d %%IMAGE%%
3333

3434
Then, access it via `http://localhost:8080` or `http://host-ip:8080` in a browser.
3535

36-
If you'd like to use an external database instead of a `mysql` container, specify the hostname and port with `WORDPRESS_DB_HOST` along with the password in `WORDPRESS_DB_PASSWORD` and the username in `WORDPRESS_DB_USER` (if it is something other than `root`):
37-
38-
```console
39-
$ docker run --name some-%%REPO%% -e WORDPRESS_DB_HOST=10.1.2.3:3306 \
40-
-e WORDPRESS_DB_USER=... -e WORDPRESS_DB_PASSWORD=... -d %%IMAGE%%
41-
```
42-
4336
When running WordPress with TLS behind a reverse proxy such as NGINX which is responsible for doing TLS termination, be sure to set `X-Forwarded-Proto` appropriately (see ["Using a Reverse Proxy" in "Administration Over SSL" in upstream's documentation](https://wordpress.org/support/article/administration-over-ssl/#using-a-reverse-proxy)). No additional environment variables or configuration should be necessary (this image automatically adds the noted `HTTP_X_FORWARDED_PROTO` code to `wp-config.php` if *any* of the above-noted environment variables are specified).
4437

4538
If your database requires SSL, [WordPress ticket #28625](https://core.trac.wordpress.org/ticket/28625) has the relevant details regarding support for that with WordPress upstream. As a workaround, [the "Secure DB Connection" plugin](https://wordpress.org/plugins/secure-db-connection/) can be extracted into the WordPress directory and the appropriate values described in the configuration of that plugin added in `wp-config.php`.
@@ -49,7 +42,7 @@ If your database requires SSL, [WordPress ticket #28625](https://core.trac.wordp
4942
As an alternative to passing sensitive information via environment variables, `_FILE` may be appended to the previously listed environment variables, causing the initialization script to load the values for those variables from files present in the container. In particular, this can be used to load passwords from Docker secrets stored in `/run/secrets/<secret_name>` files. For example:
5043

5144
```console
52-
$ docker run --name some-wordpress -e WORDPRESS_DB_PASSWORD_FILE=/run/secrets/mysql-root ... -d %%IMAGE%%:tag
45+
$ docker run --name some-%%REPO%% -e WORDPRESS_DB_PASSWORD_FILE=/run/secrets/mysql-root ... -d %%IMAGE%%:tag
5346
```
5447

5548
Currently, this is supported for `WORDPRESS_DB_HOST`, `WORDPRESS_DB_USER`, `WORDPRESS_DB_PASSWORD`, `WORDPRESS_DB_NAME`, `WORDPRESS_AUTH_KEY`, `WORDPRESS_SECURE_AUTH_KEY`, `WORDPRESS_LOGGED_IN_KEY`, `WORDPRESS_NONCE_KEY`, `WORDPRESS_AUTH_SALT`, `WORDPRESS_SECURE_AUTH_SALT`, `WORDPRESS_LOGGED_IN_SALT`, `WORDPRESS_NONCE_SALT`, `WORDPRESS_TABLE_PREFIX`, and `WORDPRESS_DEBUG`.
@@ -62,27 +55,65 @@ Run `docker stack deploy -c stack.yml %%REPO%%` (or `docker-compose -f stack.yml
6255

6356
This image does not provide any additional PHP extensions or other libraries, even if they are required by popular plugins (e.g. [it cannot send e-mails](https://github.com/docker-library/wordpress/issues/30)). There are an infinite number of possible plugins, and they potentially require any extension PHP supports. Including every PHP extension that exists would dramatically increase the image size.
6457

65-
If you need additional PHP extensions, you'll need to create your own image `FROM` this one. The [documentation of the `php` image](https://github.com/docker-library/docs/blob/master/php/README.md#how-to-install-more-php-extensions) explains how to compile additional extensions. Additionally, the [`wordpress` Dockerfile](https://github.com/docker-library/wordpress/blob/618490d4bdff6c5774b84b717979bfe3d6ba8ad1/apache/Dockerfile#L5-L9) has an example of doing this.
66-
67-
The following Docker Hub features can help with the task of keeping your dependent images up-to-date:
68-
69-
- [Automated Builds](https://docs.docker.com/docker-hub/builds/) let Docker Hub automatically build your Dockerfile each time you push changes to it.
58+
If you need additional PHP extensions, you'll need to create your own image `FROM` this one. The [documentation of the `php` image](https://github.com/docker-library/docs/blob/master/php/README.md#how-to-install-more-php-extensions) explains how to compile additional extensions. Additionally, [an older `Dockerfile` for `%%IMAGE%%`](https://github.com/docker-library/wordpress/blob/618490d4bdff6c5774b84b717979bfe3d6ba8ad1/apache/Dockerfile#L5-L9) has a simplified example of doing this and [a newer version of that same `Dockerfile`](https://github.com/docker-library/wordpress/blob/5bbbfa8909232af10ea3fea8b80302a6041a2d04/latest/php7.4/apache/Dockerfile#L18-L62) has a much more thorough example.
7059

7160
## Include pre-installed themes / plugins
7261

73-
Mount the volume containing your themes or plugins to the proper directory; and then apply them through the wp-admin webui. Ensure read/write/execute permissions are in place for the user.
62+
Mount the volume containing your themes or plugins to the proper directory; and then apply them through the "wp-admin" UI. Ensure read/write/execute permissions are in place for the user:
7463

7564
- Themes go in a subdirectory in `/var/www/html/wp-content/themes/`
7665
- Plugins go in a subdirectory in `/var/www/html/wp-content/plugins/`
7766

67+
If you wish to provide additional content in an image for deploying in multiple installations, place it in the same directories under `/usr/src/wordpress/` instead (which gets copied to `/var/www/html/` on the container's initial startup).
68+
69+
## Static image / updates-via-redeploy
70+
71+
The default configuration for this image matches the official WordPress defaults in which automatic updates are enabled (so the initial install comes from the image, but after that it becomes self-managing within the `/var/www/html/` data volume).
72+
73+
If you wish to have a more static deployment (similar to other containerized applications) and deploy new containers to update WordPress + themes/plugins, then you'll want to use something like the following (and run the resulting image read-only):
74+
75+
```dockerfile
76+
FROM %%IMAGE%%:apache
77+
WORKDIR /usr/src/wordpress
78+
RUN set -eux; \
79+
find /etc/apache2 -name '*.conf' -type f -exec sed -ri -e "s!/var/www/html!$PWD!g" -e "s!Directory /var/www/!Directory $PWD!g" '{}' +; \
80+
cp -s wp-config-docker.php wp-config.php
81+
COPY custom-theme/ ./wp-content/themes/custom-theme/
82+
COPY custom-plugin/ ./wp-content/plugins/custom-plugin/
83+
```
84+
85+
For FPM-based images, remove the `find` instruction and adjust the `SCRIPT_FILENAME` paths in your reverse proxy from `/var/www/html` to `/usr/src/wordpress`.
86+
87+
Run the result read-only, providing writeable storage for `/tmp`, `/run`, and (optionally) `wp-content/uploads`:
88+
89+
```console
90+
$ docker run ... \
91+
--read-only \
92+
--tmpfs /tmp \
93+
--tmpfs /run \
94+
--mount type=...,src=...,dst=/usr/src/wordpress/wp-content/uploads \
95+
... \
96+
--env WORDPRESS_DB_HOST=... \
97+
--env WORDPRESS_AUTH_KEY=... \
98+
--env ... \
99+
custom-wordpress:tag
100+
```
101+
102+
**Note:** be sure to rebuild and redeploy regularly to ensure you get all the latest WordPress security updates.
103+
78104
## Running as an arbitrary user
79105

80-
See [the "Running as an arbitrary user" section of the `php` image documentation](https://hub.docker.com/_/php/).
106+
See [the "Running as an arbitrary user" section of the `php` image documentation](https://github.com/docker-library/docs/blob/master/php/README.md#running-as-an-arbitrary-user).
81107

82108
When running WP-CLI via the `cli` variants of this image, it is important to note that they're based on Alpine, and have a default `USER` of Alpine's `www-data`, whose UID is `82` (compared to the Debian-based WordPress variants whose default effective UID is `33`), so when running `%%IMAGE%%:cli` against an existing Debian-based WordPress install, something like `--user 33:33` is likely going to be necessary (possibly also something like `-e HOME=/tmp` depending on the `wp` command invoked and whether it tries to use `~/.wp-cli`). See [docker-library/wordpress#256](https://github.com/docker-library/wordpress/issues/256) for more discussion around this.
83109

84110
## Configuring PHP directives
85111

86-
See [the "Configuration" section of the `php` image documentation](https://hub.docker.com/_/php/).
112+
See [the "Configuration" section of the `php` image documentation](https://github.com/docker-library/docs/blob/master/php/README.md#configuration).
87113

88-
For example, to adjust common `php.ini` flags like `upload_max_filesize`, you could create a `custom.ini` with the desired parameters and place it in the `$PHP_INI_DIR/conf.d/` directory.
114+
For example, to adjust common `php.ini` flags like `upload_max_filesize`, you could create a `custom.ini` with the desired parameters and place it in the `$PHP_INI_DIR/conf.d/` directory:
115+
116+
```dockerfile
117+
FROM %%IMAGE%%:tag
118+
COPY custom.ini $PHP_INI_DIR/conf.d/
119+
```

0 commit comments

Comments
 (0)