Custom Docker image for Wordpress.
Provides full database configuration, memcached and LDAP support and WP-CLI.
WordPress is open source software you can use to create a beautiful website, blog, or app.
https://hub.docker.com/r/monogramm/docker-wordpress/
Tags:
images/5.8/php7.4-apache/Dockerfile
: 5.8-apache apache 5.8 latestimages/5.8/php7.4-fpm/Dockerfile
: 5.8-fpm fpmimages/5.8/php7.4-fpm-alpine/Dockerfile
: 5.8-fpm-alpine fpm-alpineimages/5.7/php7.4-apache/Dockerfile
: 5.7-apache 5.7images/5.7/php7.4-fpm/Dockerfile
: 5.7-fpmimages/5.7/php7.4-fpm-alpine/Dockerfile
: 5.7-fpm-alpineimages/5.6/php7.4-apache/Dockerfile
: 5.6-apache 5.6images/5.6/php7.4-fpm/Dockerfile
: 5.6-fpmimages/5.6/php7.4-fpm-alpine/Dockerfile
: 5.6-fpm-alpineimages/5.5/php7.4-apache/Dockerfile
: 5.5-apache 5.5images/5.5/php7.4-fpm/Dockerfile
: 5.5-fpmimages/5.5/php7.4-fpm-alpine/Dockerfile
: 5.5-fpm-alpine
This Docker image adds LDAP and Memcached PHP Extension to official Wordpress image for WordPress plugins. It is inspired from fjudith/docker-wordpress image but also provides Apache variant.
This image does not contain the database for Wordpress. You need to use either an existing database or a database container.
This image is designed to be used in a micro-service environment. There are two versions of the image you can choose from.
The apache
tag contains a full Wordpress installation including an apache web server. It is designed to be easy to use and gets you running pretty fast. This is also the default for the latest
tag and version tags that are not further specified.
The second option is a fpm
container. It is based on the php-fpm image and runs a fastCGI-Process that serves your Wordpress page. To use this image it must be combined with any webserver that can proxy the http requests to the FastCGI-port of the container.
The apache image contains a webserver and exposes port 80. To start the container type:
$ docker run -d -p 8080:80 monogramm/docker-wordpress
Now you can access Wordpress at http://localhost:8080/ from your host system.
To use the fpm image you need an additional web server that can proxy http-request to the fpm-port of the container. For fpm connection this container exposes port 9000. In most cases you might want use another container or your host as proxy.
If you use your host you can address your Wordpress container directly on port 9000. If you use another container, make sure that you add them to the same docker network (via docker run --network <NAME> ...
or a docker-compose
file).
In both cases you don't want to map the fpm port to you host.
$ docker run -d monogramm/docker-wordpress:fpm
As the fastCGI-Process is not capable of serving static files (style sheets, images, ...) the webserver needs access to these files. This can be achieved with the volumes-from
option. You can find more information in the docker-compose section.
By default this container does not contain the database for Wordpress. You need to use either an existing database or a database container.
The Wordpress setup wizard (should appear on first run) allows connecting to an existing MySQL/MariaDB. You can also link a database container, e. g. --link my-mysql:mysql
, and then use mysql
as the database host on setup. More info is in the docker-compose section.
The Wordpress installation and all data beyond what lives in the database (file uploads, etc) are stored in the unnamed docker volume volume /var/www/html
. The docker daemon will store that data within the docker directory /var/lib/docker/volumes/...
. That means your data is saved even if the container crashes, is stopped or deleted.
To make your data persistent to upgrading and get access for backups is using named docker volume or mount a host folder. To achieve this you need one volume for your database container and Wordpress.
Wordpress:
/var/www/html/
folder where all Wordpress data lives
$ docker run -d \
-v wordpress_html:/var/www/html \
monogramm/docker-wordpress
Database:
/var/lib/mysql
MySQL / MariaDB Data
$ docker run -d \
-v db:/var/lib/mysql \
mariadb
The following environment variables are also honored for configuring your WordPress instance:
-e WORDPRESS_DB_HOST=...
(defaults to the IP and port of the linkedmysql
container)-e WORDPRESS_DB_USER=...
(defaults to "root")-e WORDPRESS_DB_PASSWORD=...
(defaults to the value of theMYSQL_ROOT_PASSWORD
environment variable from the linkedmysql
container)-e WORDPRESS_DB_NAME=...
(defaults to "wordpress")-e WORDPRESS_TABLE_PREFIX=...
(defaults to "", only set this when you need to override the default table prefix in wp-config.php)-e WORDPRESS_AUTH_KEY=...
,-e WORDPRESS_SECURE_AUTH_KEY=...
,-e WORDPRESS_LOGGED_IN_KEY=...
,-e WORDPRESS_NONCE_KEY=...
,-e WORDPRESS_AUTH_SALT=...
,-e WORDPRESS_SECURE_AUTH_SALT=...
,-e WORDPRESS_LOGGED_IN_SALT=...
,-e WORDPRESS_NONCE_SALT=...
(default to unique random SHA1s)
If the WORDPRESS_DB_NAME
specified does not already exist on the given MySQL server, it will be created automatically upon startup of the wordpress
container, provided that the WORDPRESS_DB_USER
specified has the necessary permissions to create it.
This version will use the apache image and add a MariaDB container (you can also use MySQL if you prefer). The volumes are set to keep your data persistent. This setup provides no ssl encryption and is intended to run behind a proxy.
Make sure to set the variables MYSQL_ROOT_PASSWORD
, MYSQL_PASSWORD
, DOLI_DB_PASSWORD
and DOLI_DB_ROOT_PASSWORD
before you run this setup.
Create docker-compose.yml
file as following:
version: '2'
volumes:
wordpress_html:
wordpress_db:
services:
mariadb:
image: mariadb:latest
restart: always
volumes:
- wordpress_db:/var/lib/mysql
environment:
- "MYSQL_ROOT_PASSWORD="
- "MYSQL_PASSWORD="
- "MYSQL_DATABASE=wordpress"
- "MYSQL_USER=wordpress"
wordpress:
image: monogramm/docker-wordpress
restart: always
depends_on:
- mariadb
ports:
- "8080:80"
environment:
- "WORDPRESS_DB_HOST=mariadb"
- "WORDPRESS_DB_NAME=wordpress"
- "WORDPRESS_DB_USER=wordpress"
- "WORDPRESS_DB_PASSWORD="
volumes:
- wordpress_html:/var/www/html
Then run all services docker-compose up -d
. Now, go to http://localhost:8080 to access the new Wordpress installation wizard.
When using the FPM image you need another container that acts as web server on port 80 and proxies the requests to the Wordpress container.
In this example a simple nginx container is combined with the monogramm/docker-wordpress:fpm
image. The data is stored in docker volumes. The nginx container also need access to static files from your Wordpress installation. It gets access to all the volumes mounted to Wordpress via the volumes_from
option. The configuration for nginx is stored in the configuration file nginx.conf
, that is mounted into the container.
As this setup does not include encryption it should to be run behind a proxy.
Make sure to set the variables POSTGRES_PASSWORD
and DOLI_DB_PASSWORD
before you run this setup.
Create docker-compose.yml
file as following:
version: '2'
volumes:
wordpress_html:
wordpress_db:
services:
memcached:
image: memcached
mariadb:
image: mariadb:latest
restart: always
volumes:
- wordpress_db:/var/lib/mysql
environment:
- "MYSQL_ROOT_PASSWORD="
- "MYSQL_PASSWORD="
- "MYSQL_DATABASE=wordpress"
- "MYSQL_USER=wordpress"
wordpress:
image: monogramm/docker-wordpress:fpm
depends_on:
- mariadb
ports:
- "9000:9000"
environment:
- "WORDPRESS_DB_HOST=mariadb"
- "WORDPRESS_DB_NAME=wordpress"
- "WORDPRESS_DB_USER=wordpress"
- "WORDPRESS_DB_PASSWORD="
volumes:
- wordpress_html:/var/www/html
web:
image: nginx
ports:
- 8080:80
links:
- wordpress
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
volumes_from:
- wordpress
restart: always
In order for this work, you must provide a valid NGinx config. Take a look at fjudith/docker-wordpress to get some sample configuration.
Then run all services docker-compose up -d
. Now, go to http://localhost:8080 to access the new Wordpress installation wizard.
Until here your Wordpress is just available from you docker host. If you want you Wordpress available from the internet adding SSL encryption is mandatory.
There are many different possibilities to introduce encryption depending on your setup.
We recommend using a reverse proxy in front of our Wordpress installation. Your Wordpress will only be reachable through the proxy, which encrypts all traffic to the clients. You can mount your manually generated certificates to the proxy or use a fully automated solution, which generates and renews the certificates for you.
Once the initial site configuration performed, navigate to Plugins
, activate WP-FFPC
and click Settings
.
Set the following minimal configuration options:
- Cache Type/Select Backend: PHP Memcached
- Backend Settings/Hosts: memcached:11211
- Backend Settings/Authentication: username: Empty
- Backend Settings/Authentication: password: Empty
- Backend Settings/Enable memcached binary mode: Activated
You can also open a terminal session in the wordpress
container to edit the config.
wordpress_command() {
docker exec -it --user www-data wordpress wp "$@"
}
WPFFPC_SETTINGS={
WPFFPC_SETTINGS=$"$WPFFPC_SETTINGS\"cache_type\": \"memcached\""
WPFFPC_SETTINGS=$"$WPFFPC_SETTINGS, \"hosts\": \"memcached:11211\""
WPFFPC_SETTINGS=$"$WPFFPC_SETTINGS, \"memcached_binary\": \"1\""
WPFFPC_SETTINGS=$"$WPFFPC_SETTINGS, \"authuser\": \"\""
WPFFPC_SETTINGS=$"$WPFFPC_SETTINGS, \"authpass\": \"\""
WPFFPC_SETTINGS="$WPFFPC_SETTINGS}"
wordpress_command option add wp-ffpc "$WPFFPC_SETTINGS" --format=json
Because the docker-compose
levegare persistent volume in the Wordpress root directory, its required to open a session in a cli
container in order to run the command wp core update
.
Open a terminal session in the wordpress
container.
docker exec --user www-data wordpress bash
Run the following commands to update the application engine, the plugins and themes.
wp core update
wp plugins update --all
wp theme update --all
Run the following commands
docker exec --user www-data wordpress bash -c 'wp core update && wp plugins update --all && wp theme update --all'
If the image does not include the packages you need, you can easily build your own image on top of it.
Start your derived image with the FROM
statement and add whatever you like.
FROM monogramm/docker-wordpress:apache
RUN ...
You can also clone this repository and use the update.sh shell script to generate a new Dockerfile based on your own needs.
For instance, you could build a container based on Wordpress develop branch by setting the update.sh
versions like this:
versions=( "master" )
Then simply call update.sh script.
bash update.sh
Your Dockerfile(s) will be generated in the images/master
folder.
If you use your own Dockerfile you need to configure your docker-compose file accordingly. Switch out the image
option with build
. You have to specify the path to your Dockerfile. (in the example it's in the same directory next to the docker-compose file)
app:
build: .
links:
- db
restart: always
Updating your own derived image is also very simple. When a new version of the Wordpress image is available run:
docker build -t your-name --pull .
docker run -d your-name
or for docker-compose:
docker-compose build --pull
docker-compose up -d
The --pull
option tells docker to look for new versions of the base image. Then the build instructions inside your Dockerfile
are run on top of the new image.
If you got any questions or problems using the image, please visit our Github Repository and write an issue.