Sign inSign up

unibz/wordpress

By unibz

•Updated over 7 years ago

WordPress

Image
0

3.4K

unibz/wordpress repository overview

⁠Docker image for WordPress

This documentation describes the WordPress Docker image alone.

⁠Step 0: prerequisites

  1. Clone this repo.
  2. Build this image (for the next examples we will use tag unibz\wordpress:3.1.0, you have to update it to your needs): cd docker && docker build -t unibz/wordpress:3.1.0 .
  3. Have mysql up and running with a database and a user ready.

Once you built the image, for each new WordPress instance that you want to create, two steps are required:

  1. run the image using as entrypoint the initialization script /entrypoint-init.sh (it will inizialize stuff and then terminate)
  2. run the image using the default settings

⁠Step 1: initialization

The initialization run expects to find an empty volume mounted on /root. The reason for that, is that the init entrypoint will just initialize WordPress using the default directory /var/www/html and finally copy all files to /root. After copying, the init entrypoint terminates and the volume and the database are ready to be attached to the final container.

Note: the apache log files directory is also copied to the volume.

For initialization, a number of environment variables is required:

  • MYSQL_HOST: the host where the MySQL database is located
  • MYSQL_USER: the username for the connection to MySQL
  • MYSQL_PASS: the password for the connection to MySQL
  • MYSQL_NAME: the name of the database
  • WP_FQDN: the fully qualified domain name that this WordPress is going to use
  • WP_NAME: the title of the WordPress blog
  • WP_ADMIN_USER: the username of the WordPress admin
  • WP_ADMIN_MAIL: the email of the WordPress admin
  • WP_ADMIN_PASS: the password of the WordPress admin
  • ICTADMIN_USERNAME: the username of the ICT WordPress admin
  • ICTADMIN_EMAIL: the email of the ICT WordPress admin
  • ICTADMIN_PASSWORD: the password of the ICT WordPress admin

The following variables are optional:

  • INSTANCE_SUPPORTED: if set to 1, the wordpress instance created will be supported (theme and plugins will be installed automatically, some default settings will be applied automatically)
  • EXPIRY_DATE: optional text that will be added to /root/container-data.txt to identify the date after which the website can be decommissioned
  • REQUEST_ID: optional text that will be added to /root/container-data.txt to identify the ticket that originates the current website

You can use this command as reference for running the initialization container:

$ docker run                                 \
    --rm                                     \ # removes the init container after termination
    -it                                      \ # in case of errors they will be printed to stdout
    --entrypoint=/entrypoint-init.sh         \ # override the default entrypoint
    --name test.local-init                   \ # container name
    -h test.local                            \ # FQDN to instruct docker how to name the container
    --link mariadb.local:mariadb.local       \ # used for mac os only (no linux), only in case the database is another container
    -v /path/to/volume/test.local:/root      \ # bind mount of a volume to the container /root directory
    -e MYSQL_HOST=mariadb.local              \ # mysql host
    -e MYSQL_USER=wp_user                    \ # mysql username
    -e MYSQL_PASS=wp_pass                    \ # mysql password
    -e MYSQL_NAME=wp_db                      \ # mysql database name
    -e WP_FQDN=test.local                    \ # FQDN to instruct WordPress on what address to listen on
    -e WP_NAME=Test                          \ # WordPress blog title
    -e WP_ADMIN_USER=giuroman                \ # WordPress admin username
    -e [email protected]      \ # WordPress admin email address
    -e WP_ADMIN_PASS=secret111               \ # WordPress admin password
    -e ICTADMIN_USERNAME=ictadmin            \ # ICT WordPress admin username
    -e [email protected]            \ # ICT WordPress admin email address
    -e ICTADMIN_PASSWORD=password123         \ # ICT WordPress admin password
    -e INSTANCE_SUPPORTED=1                  \ # Supported instance (optional)
    -e EXPIRY_DATE=2099-12-31                \ # Expiry date (optional)
    -e REQUEST_ID=123456                     \ # ID of the ticket behind this website (optional)
    unibz/wordpress:3.1.0

The initialization script returns the following status codes on exit:

  1. ok
  2. mandatory environment variable missing
  3. wp-cli was unable to download, install and configure wordpress
  4. could not copy /var/www/html to volume
  5. could not copy /var/log/apache2 to volume

⁠Step 2: run the image

Now that the volume and the database were initialized, they preserve the state of the WordPress site, and the final container can be started. To run successfully, the container expects subdirectories of the volume used in step 1 to be mounted to different places:

File/directory on the hostMount point in the container
/path/to/volume/container-data.txt/root/container-data.txt
/path/to/volume/html/var/www/html
/path/to/volume/apache2/var/log/apache2

Use this command as reference for running the container:

$ docker run                                                                  /
    -d                                                                        / # substitute to -it in case you need to debug this step
    --name test.local                                                         / # container name
    -h test.local                                                             / # FQDN to instruct docker how to name the container
    --link mariadb.local:mariadb.local                                        / # optional: just in case your database is another container
    -p 80:80                                                                  / # expose port 80 on the host and bind it to port 80 on the container
    -v /path/to/volume/test.local/container-data.txt:/root/container-data.txt / # the existence of this file is a flag to tell the container that it can start
    -v /path/to/volume/test.local/html:/var/www/html                          / # web root
    -v /path/to/volume/test.local/apache2:/var/log/apache2                    / # apache log directory
    --restart always                                                          / # auto restart in case of crash
    unibz/wordpress:3.1.0

If the container terminates with status code 1, it means that the file /root/container-data.txt was not found, meaning that you are trying to use a volume that has not beed initialized.

Tag summary

Content type

Image

Digest

Size

110.2 MB

Last updated

over 7 years ago

docker pull unibz/wordpress:3.2.2