WordPress development on Docker
This image provides WordPress on PHP7. It is based on the official WordPress
Docker image but adds WP-CLI, PHPUnit, Xdebug, and the WordPress unit testing
docker pull chriszarate/wordpress
Most likely, you will want to connect this image to a MySQL / MariaDB container
and add your plugin or theme code, allowing you to connect to a development
instance of WordPress in a browser. If that's the case, I can recommend my
Docker Compose WordPress development repo.
WORDPRESS_ACTIVATE_PLUGINS: A space-separated list of plugin paths relative
/var/www/html/wp-content/plugins/that should be activated when the
container starts. If a plugin cannot be found, an install will be attempted
wp plugin install.
WORDPRESS_ACTIVATE_THEMEA theme path relative to
that should be activated when the container starts. If the theme cannot be
found, an install will be attempted via
wp theme install.
WORDPRESS_CONFIG_EXTRA: Additional PHP to append to
WORDPRESS_DB_HOST: Default "mysql".
WORDPRESS_DB_NAME: Default "wordpress".
WORDPRESS_DB_USER: Default "root".
WORDPRESS_DB_PASSWORD: Default "".
WORDPRESS_PERMALINK_STRUCTURE: Default "/%year%/%monthnum%/%postname%/"
WORDPRESS_SITE_USER: Default "wordpress"
WORDPRESS_SITE_PASSWORD: Default "wordpress"
WORDPRESS_SITE_EMAIL: Default "firstname.lastname@example.org"
WORDPRESS_SITE_TITLE: Default "Project".
WORDPRESS_SITE_URL: Default "http://project.dev".
Assuming you are running in the context of Docker Compose:
docker-compose exec --user www-data wordpress wp [command]
Running tests (PHPUnit)
Previous versions of this image provided PHPUnit inside the container. However,
bundling a single version of PHPUnit was not very flexible. Additionally, users
did not have the opportunity to install their own test dependencies. I now
provide a(n optional) separate PHPUnit WordPress container that provides much
greater flexibility and isolation. Please see the README of my
Docker Compose WordPress development repo for instructions on how
to set this up.
Xdebug is installed but needs the IP of your local machine to connect to your
local debugging client. Edit
.env and populate the
environment variable with your machine's (local network) IP address. The default
XDEBUG_CONFIG: "remote_host=x.x.x.x idekey=xdebug"
You can enable profiling by appending additional instructions, e.g.:
XDEBUG_CONFIG: "remote_host=x.x.x.x idekey=xdebug profiler_enable=1 profiler_output_name=%R.%t.out"
This will output cachegrind files (named after the request URI and timestamp) to
/tmp inside the WordPress container.
You can seed
wp-content with files (e.g., an uploads folder) by mounting a
/tmp/wordpress/init-wp-content. Everything in that folder will be
copied to your installation's