Categories
Uncategorized

Setting up a WordPress dev env with Docker

This post talks about the process I went through to setup my multi-plugin dev env, I need to be able to write code in Gutenberg, WooCommerce Gutenberg Products Blocks, WooCommerce Admin and WooCommerce Core.

Note: using @wordpress/env is infinitely better once it’s out and fully stable and documented, Enrique has done some great work on it and I plan into fully migrating to it soon.

Prerequisite

Setting up folders

This is just a personal preference, I keep a home folder named work that holds all of the projects I’m working on, it makes switching easier.

I make sure no 2 folders have the same 2 first letters, it makes autocomplete much easier, but you end with bergs-woo and admin-wc.

Setting up WordPress Develop

Each project you will work has his own setup process, it will mostly be clone, npm install, composer install, npm run build.

This is how you setup WordPress Develop

Note: WordPress Develop has its own docker file, but I’m ignoring that for now.

  1. git clone https://github.com/WordPress/wordpress-develop wordpress
  2. npm install
  3. npm run build

This should get you up & running with a trunk version of WordPress, ensuring you get the latest updates.

Setting up Docker

You installed Docker with docker-compose, you have all of your projects set, now it’s time to run them, you will need a docker-compose file, I’m using this file, courtesy to Riad Benguella.

Have that file somewhere, it doesn’t matter where it is since everything is absolute in it, after that, you can run it using:

docker-compose up -d

If you’re running this command for the first time, it will take some time to download the WordPress image, more info into how you can configure it inside that link.

Great, now you should have a WordPress website running at http://localhost:8889, if it doesn’t work like magic, the most probable thing is that 8889 is already used by another process, check who’s using that port by running:

sudo lsof -i tcp:8889

You can also change your port to something else in the docker-compose file.

Switching WordPress versions

If you feel like using another version of WordPress other than trunk, like the stable version or an older version for testing, you can do this:

Prerequisite (only done once, do it again each release)

git fetch --all --tags --prune

Then:

  1. git checkout tags/5.3.0
  2. npm run build
    for older versions than 5.3, run npm run grunt instead
  3. cd back to the docker-compose.yml file and run docker-compose stop
  4. docker-compose start
  5. WordPress will ask for a DB update, confirm that.

Congrash, you’re using said version of WordPress.