Expanded from https://github.com/lumonald/existing-wordpress-development-docker. Minor changes to ports, specify new URL, and addition of phpMyAdmin.
Brings up an existing WordPress site from wp-content
and a MySQL backup. Allows changing the configured URL, which speeds up developing on a local machine or easily switching domains. By default it will start on http://localhost:8000 for local preview.
Requires Docker and docker-compose. Since the wordpress image includes an Apache webserver it would be possible to pare this down further e.g. by exposing the container on default web port 80, but to avoid conflicts and allow deployment with an nginx proxy the default port is 8000.
The docker-compose.yml
file defines 2 containers -
wordpress
- for the website files.db
- for the associated MySQL database.
In addition, docker-compose-phpmyadmin.yml
starts a phpMyAdmin interface to interact with the database.
To run this alongside the site, use e.g:
docker-compose -f docker-compose.yml -f docker-compose-phpmyadmin.yml up
The wordpress
container has 2 volumes -
-
The
site/wp-content
folder - Copy thewp-content
folder from the production site. It's used for all customisations outside of the core WordPress code. This includes the themes, plugins, uploads etc. -
init/prep.sh
- Disables plugins as defined in the.env
file. It also makes thewp-content
folder the same owner/group as the rest of the site.
Note: The wp-config.php
file gets auto generated for this local WordPress instance.
The db
container has 3 volumes -
-
database
- A folder for all of the MySQL files, this gets automatically generated by docker and can remain untouched for average usage. -
mysqldumps/backup.sql.gz
- This is a snapshot taken from the production instance via mysqldump, place the file in this location and it will get imported on the first run of the container automatically. -
init/migrate.sh
- A URL migration script, this updates the URL stored in the database, this also gets run automatically when the containers are spun up for the first time.
-
Clone or download this project.
-
Create a mysqldump from your pre-existing site and place in location:
mysqldumps/backup.sql.gz
(ensure file is namedbackup.sql.gz
) -
Obtain copy of
wp-content
folder from pre-existing site and place in location:site/wp-content
-
Copy
env-template
as.env
and enter your configuration variables. -
Navigate to the root of this project locally and run:
docker-compose up -d && docker-compose exec wordpress prep.sh
-
For additional insight into the database, optionally run phpMyAdmin with:
docker-compose -f docker-compose.yml -f docker-compose-phpmyadmin.yml up
By default, the website will then be available at http://localhost:8000
and the WordPress dashboard at http://localhost:8000/wp-admin
. phpMyAdmin is set to http://localhost:8001
. If you specified a different new_url
in the .env
file then wordpress will attempt to redirect there, so you may require some DNS and webserver configuration to bring the site up. Below is a minimal example for running an nginx reverse proxy in front of wordpress:
server {
server_name example.com;
location / {
proxy_pass http://localhost:8000/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
}
}