Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romuloctba/f55763c60a484147eae753accd9d7855 to your computer and use it in GitHub Desktop.
Save romuloctba/f55763c60a484147eae753accd9d7855 to your computer and use it in GitHub Desktop.
WordPress development quick and ease, using Docker and Kitematic

Creating the quick Dev env

This method creates quickly new WP Instances and is great for testing, developping, and trying things without messing 'real' installations.

This aproach uses Docker as container system, and we will run 1 container with WP and another for the DB.

  1. Install docker. Since I had many problems using Docker for Windows (dont judge), I used Docker Toolbelt utility: https://docs.docker.com/toolbox/overview/#ready-to-get-started

    • It will install docker for windows, virtualbox (to run the image in a linux env.) and Kitematic Alpha. Kitematic is the GUI for using Docker in an easy (cheat) way

All we are doing from now on will be on Kitematic, but the steps could be easily reproduced using docker-compose

  1. Open kitematic. If on windows, for it to work, make sure to have HyperV activated ( https://docs.microsoft.com/pt-br/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v)

    • If it does n not work, allow it to use virtual box.
  2. Add new Container WordPress, oficial image ( https://hub.docker.com/r/library/wordpress/ ) - To make the data persist and allow editing of WP files directly on the file system, click on the 'Volumes' widget, at the folder icon that says /var/www/html, and allow it to enable volumes.

  3. Add new Container MySQL, also oficial image ( https://hub.docker.com/r/library/mysql/ )

4a. On the MySQL Container, let's add the database, user and password. Set the following variables:

  • MYSQL_DATABASE wp
  • MYSQL_USER wp
  • MYSQL_PASSWORD wp

Attention: the mysql will NOT persist the data, unless we atach it to a backup runner.

I used to persist mysql data using container, but its been more than a year now, and apparently it cannot be done anymore.

4a. Freeze MySQL Port: On MySQL container, click on the gear/settings -> Hostname/Ports then make sure that Docker port is 3306 and Publshed IP/Port is the same as the one in ACCESS URL (container home page, when on)

  1. On Kitematic, click to open the Browser on the WordPress container. It will open the WP Setup. Let's fill it with the values we just setup.

Important: To find the Database Host, use the value Kitematic shows as ACCESS URL, right on "IP & Ports" widget at the MySQL container home page on Kitematic

- Database Name	 wp
- Username	wp
- Password	wp
- Database Host	192.168.99.100:3306
- Table Prefix	_wp

Backing up MySQL Data

As I mentioned, the MySQL data will not persist by simply adding a volume, as the WP files do.

In order to save the database data, we need to make use of another image, called mysql-backup.

  1. Add new Image, mysql-backup ( https://hub.docker.com/r/confirm/mysql-backup/ )

  2. Go to Settings -> Network and in the Link section, choose the mysql container to be linked to the new image. Alias can be mysql or whatever. Remember to click (+) so it adds the link

  3. Add Volumes support to the mysql-backup image: Go to Settings -> Volumes

The container will now start, and will make a backup from the MySQL container you just linked.

Restoring Backed Up data to MySQL Container

The same tool we just used, mysql-backup, can be used to restore the data to the mysql container.

To do that, simply set the variable MODE at the mysql-backup container

The possible values are: BACKUP or RESTORE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment