WordPress Docker Local Development

Wordpress Docker Local DevelopmentPhoto by Sebastian Herrmann on Unsplash

Quick Docker config file and tips for setting up WordPress local development for an existing WordPress website.

I needed to make some quick code updates to an existing WordPress website so I wanted to spool up a local instance using Docker but I didn’t find an example of anyone doing the two things I consider critical: importing a database SQL dump and importing the WordPress files to edit in the wp-content directory. Here’s what I think is best practice:

Install Docker

Install Docker.

Add your local domain name

Edit your hosts file to add your local domain:

Your existing website files

Create a new directory named mywebsite-wordpress to host your local development and open it.

Create a new subdirectory database/docker-entrypoint-initdb.d/ and copy your database SQL dump into it.

Create a new subdirectory wp-content/ and copy your WordPress wp-content (e.g. themes, plugins, uploads) into it.

docker-compose.yaml

This is the docker-compose.yaml configuration file that I suggest to make everything work:

Create this docker-compose.yaml in your local development directory and paste this in:

Notes

Your SQL dump(s) can be named anything so long as they are in the ./database/docker-entrypoint-initdb.d directory.

Your WordPress website domain name is changed to wordpress.localhost (without the need to edit the SQL dump or database).

Debugging is enabled (WordPress debug errors are displayed as messages on the local website and in a log file in ./wp-content/debug.log

Go

Start Docker with:

This will import your SQL dump and your WordPress files and use Docker volumes for the database and WordPress standard files.

Edit

Visit http://wordpress.localhost in your browser to confirm your website is working locally.

Edit your files (e.g. themes, plugins) in the wp-content/ directory.

Stop

Stop Docker with:

 

Leave a message:

Your email address will not be published. Required fields are marked *