Local development

This how-to will guide you through creating a classic WordPress project, containerising it and running it locally using docker compose

Requirements

Bootstrap the project

First let’s create a project via wp-cli.

$ mkdir -p my-site/wp-content/{plugins,themes,mu-plugins,uploads}
$ cd my-site

Then we need to install the Bitpoke Stack must use plugin for WordPress from GitHub .

In order to enable the external object cache, we need to place it into our WP_CONTENT_DIR/object-cache.php.

$ ln -sf mu-plugins/stack-mu-plugin/src/object-cache.php web/app/object-cache.php

Create the Dockerfile

Bitpoke Stack provides a base image for building and developing WordPress sites. https://hub.docker.com/r/bitpoke/wordpress-runtime/tags is used as a builder and runtime image.

The Dockerfile is as simple as:

FROM docker.io/bitpoke/wordpress-runtime:5.8.2

Run using docker-compose

This docker-compose.yaml is a good starting point for local development using docker.

version: "3.3"

services:
  wordpress:
    depends_on:
      - db
      - memcached
    image: docker.io/bitpoke/wordpress-runtime:5.8.2
    volumes:
      - ./config:/app/config
      - ./wp-content:/app/web/wp-content
    ports:
      - "8080:8080"
    restart: always
    environment:
      DB_HOST: db:3306
      DB_USER: wordpress
      DB_PASSWORD: not-so-secure
      DB_NAME: wordpress
      MEMCACHED_HOST: memcached:11211
      WP_HOME: http://localhost:8080
      WP_SITEURL: http://localhost:8080/wp
      WP_ENV: development

  db:
    image: percona:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: not-so-secure
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: not-so-secure

  memcached:
    image: memcached:1.5

volumes:
  db_data: {}

To boot up WordPress and MySQL server run:

docker-compose up -d

This site should be available at http://localhost:8080.

Installing a plugin (optional)

To install a plugin you can just:

docker-compose run wordpress wp plugin install debug-bar

What’s next